Regex anchors inside character class

前端 未结 3 1003
囚心锁ツ
囚心锁ツ 2020-12-20 17:51

Is it possible to use anchors inside a character class? This doesn\'t work:

analyze-string(\'abcd\', \'[\\s^]abcd[\\s$]\') 

It looks like <

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 18:49

    Using the caret after the first square bracket will negate the character class. It essentially gives you the opposite of what you're looking to do, meaning the character class will match any character that is not in the character class. Negated character classes also match (invisible) line break characters.

    You could try doing a negative look-ahead possibly.

    (?!\s)
    

提交回复
热议问题