Case sensitive and insensitive in the same pattern

百般思念 提交于 2019-11-29 10:06:16

Yes! You can in fact do this in some flavors, using what is called embedded modifier. This puts the modifier in the pattern, and you can essentially select which parts of the pattern the modifiers apply to.

The embedded modifier for case insensitivity is (?i), so the pattern you want in this case is:

<[A-Z]([A-Z]{2})(?i:\1*)>

References

  • regular-expressions.info/Modifiers
    • Specifying Modes Inside The Regular Expression
      • Instead of /regex/i, you can also do /(?i)regex/
    • Turning Modes On and Off for Only Part of The Regular Expression
      • You can also do /first(?i)second(?-i)third/
    • Modifier Spans
      • You can also do /first(?i:second)third/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!