Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 查找某些符号之间的重复项_Regex - Fatal编程技术网

Regex 查找某些符号之间的重复项

Regex 查找某些符号之间的重复项,regex,Regex,是否可以检测到字符串中有4个相同的字母被其他字符分隔,例如:abb*bbc(bb*bb)或a*aaa?我尝试了(\S+\S*)\1,它对abb*bbc很有效,但它也找到了bb和abbcd。只有(稍微难看的)regex的解决方案是: ([a-z])(?:\*\1\1|\1\*\1|\1\1\*)\1 即: ([a-z]) any letter (?: one of the following: \*\1\1| - a *, and then the letter tw

是否可以检测到字符串中有4个相同的字母被其他字符分隔,例如:
abb*bbc
bb*bb
)或
a*aaa
?我尝试了
(\S+\S*)\1
,它对
abb*bbc
很有效,但它也找到了
bb
abbcd

只有(稍微难看的)regex的解决方案是:

([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

是否必须只有一个
*
,或者可以有多个(例如
a*a*aa
)?是否必须使用纯正则表达式来完成?如果没有,您使用的是什么编程语言?我使用Python,如果我们只使用regexp就可以找到解决方案