How to only match a single instance of a character?

前端 未结 3 2055
你的背包
你的背包 2021-01-24 16:23

Not quite sure how to go about this, but basically what I want to do is match a character, say a for example. In this case all of the following would not contain ma

3条回答
  •  故里飘歌
    2021-01-24 17:20

    You may use a combination of a lookbehind and a lookahead:

    (?

    See the regex demo and the regex graph:

    Details

    • (? - a negative lookbehind that fails the match if, immediately to the left of the current location, there is a a char
    • a - an a char
    • (?!a) - a negative lookahead that fails the match if, immediately to the right of the current location, there is a a char.

提交回复
热议问题