I struggle with regular expressions, and I've been trying to make one that can match any 5-character combination of X
and O
, but ignore it if it repeats X
or O
EXACTLY 5 times.
This is what I came up with:
X{1,4}|O{1,4}
X|O{1,4}
those expressions match (I want it to ignore the XXXXX and OOOOO):
I also tried using the non-capturing group (?:)
, but it didn't work out too well.
您可以尝试以下基于断言的正则表达式。
^(?!(?:X{5}|O{5})$)(?=.*X)(?=.*O)[XO]{5}$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.