Regex Match a character which is not followed by another specific character

前端 未结 1 375
别那么骄傲
别那么骄傲 2020-12-10 19:26

I\'m writing a CodeMirror extension for Brackets. To defineSimpleCodeMode I need to do some pattern matching and I\'m trying to figure out how to achieve $subject.

e

相关标签:
1条回答
  • 2020-12-10 19:41

    While this seems to be a bad idea, I can see two ways of doing it :

    1. Searching for < followed by anything but the % character, then ignoring it

    (<)(?:[^%])

    The [^] sequence allows you to search for anything but the following character.

    The (?:) sequence is for non capturing groups.

    2. (Better, if supported) Searching for input not followed by % with a negative lookahead

    <(?!%)

    The (?!) sequence succeeds if it doesn't match the following character, but is not captured.

    If you also want to do it for %>, you can just "reverse" the first option :

    (?:[^%])(>)

    Or you need a negative lookbehind :

    (careful here, the lookahead won't work as you need to go backwards)

    (?<!%)>

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