是否可以检测到字符串中有4个相同的字母由其他字符分隔,如下所示:abb*bbc
(bb*bb
)或a*aaa
?我尝试(\S+\s*)\1
,它适用于abb*bbc
,但它也会找到bb
和abbcd
。
答案 0 :(得分:1)
(稍微丑陋)正则表达式的解决方案是:
([a-z])(?:\*\1\1|\1\*\1|\1\1\*)\1
那是:
([a-z]) any letter
(?: one of the following:
\*\1\1| - a *, and then the letter twice
\1\*\1| - letter, *, letter
\1\1\* - letter, letter, *
)
\1 the fourth letter