我从正则表达式开始(总是从我需要的网上使用)
我需要一些给出输入的东西:
Input: AAABBBCCC
Index: 012345678
Run Code Online (Sandbox Code Playgroud)
正则表达式匹配将是:
我现在的正则表达式是(A{2}|B{2}|C{2}).这不是我真正的问题,但是对于As,Bs和Cs我有不同的工作正则表达式.
我认为我应该使用一些look behind运算符但是尝试:((A{2}|B{2}|C{2})$1)或者(?<=(A{2}|B{2}|C{2}))不会工作.
注意:我的问题在于c#,如果重要的话
你确实需要环顾四周,但我会用一个积极的先行断言:
(?=(([ABC])\2))
Run Code Online (Sandbox Code Playgroud)
您的匹配结果将包含在match.Groups(1)每个match对象中.
说明:
(?= # Look ahead to check that the following matches:
( # Match and capture in group number 1:
( # Match and capture in group number 2:
[ABC] # Any letter A, B or C
) # End of capturing group 2
\2 # Now match that same letter again.
) # End of group 1. It now contains AA, BB or CC
) # End of lookahead assertion
Run Code Online (Sandbox Code Playgroud)
更简单的解决方案:
(?=(AA|BB|CC))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |