Regular expression: find range except for one letter or a range

前端 未结 2 983
忘了有多久
忘了有多久 2020-11-30 14:22

How can I use the negation within square brackets as an exception, to find e. g. everything between a-z except for the the range from m-o? [a-z^m-o]?

By

相关标签:
2条回答
  • 2020-11-30 14:49

    You should be able calculate the difference yourself.

    [a-lp-z]
    

    If the regex engine supports lookahead assertion, you could use

    (?![m-o])[a-z]
    

    but this would probably be less efficient.

    0 讨论(0)
  • 2020-11-30 14:54

    In addition to what Kenny mentions:

    1. The JDK (at least) supports this syntax:

      [a-z&&[^m-o]]

    2. A couple of engines (including the .NET framework) support this:

      [a-z-[m-o]]

    0 讨论(0)
提交回复
热议问题