Regex negation?

前端 未结 3 892
天涯浪人
天涯浪人 2021-01-04 00:29

I\'m playing Regex Golf (http://regex.alf.nu/) and I\'m doing the Abba hole. I have the following regex that matches the wrong side entirely (which is what I was trying to

3条回答
  •  孤独总比滥情好
    2021-01-04 01:26

    You can make it much shorter (and get more points) by simply using . and removing unnecessary parens:

    ^(?!.*(.)(.)\2\1)
    

    It just makes sure that there's no "abba" ("abba" here means 4 letters in that particular order we don't want to match) in any part of the string without having to match the whole word.

提交回复
热议问题