我想建立q正則表達式,匹配重複的單個字符的模式,然後相互跟隨。 例如三次相同的字符'A',然後是兩次另一個字符'B'。第二組的角色重複兩次以上並不重要。 比如,它應該匹配字符串wuzDDDFFFxji如何排除第一組的單個字符從匹配到第二組?
Full match 3-8 `DDDFF`
Group 1. 3-4 `D`
Group 2. 6-7 `F`
我已經想出以下正則表達式,但有一個限制。
(.)\1{2}(.)\2{1}
它幾乎可以工作,但它不會排除在第二組中匹配的第一組人物。字符串qwuiuQQQQQsas將被匹配,因爲:
Full match 5-10 `QQQQQ`
Group 1. 5-6 `Q`
Group 2. 8-9 `Q`
這不符合我想要什麼,但我找不到正確的語法從另一個被匹配排除特定的羣體。我最近的嘗試似乎沒有工作
(.)\1{2}((?:\1))\2{1}
1st Capturing Group (.)
. matches any character (except for line terminators)
\1{2} matches the same text as most recently matched by the 1st capturing group
{2} Quantifier — Matches exactly 2 times
2nd Capturing Group ((?:\1))
Non-capturing group (?:\1)
\1 matches the same text as most recently matched by the 1st capturing group
\2{1} matches the same text as most recently matched by the 2nd capturing group
{1} Quantifier — Matches exactly one time (meaningless quantifier)
這裏的任何提示?非常感謝!
什麼是正則表達式的味道/編程語言/工具?爲什麼最後的模式沒有工作? –
如果您想避免與'qwuiuQQQQQsas'中的任何內容匹配,請嘗試['(。)\ 1 {2}((?!\ 1)。)\ 2'](https://regex101.com/r/rjRNik/1) ' –