我正在寻找一个正则表达式来匹配两个a
或两个b
之间但不在 ana
和 a之间的每个字符b
。
例如:
accccca → should match
bfffffb → should match
azzzzzb → shouldn't match
bttttta → shouldn't match
ammbmma → should match from the a to the a
bllalla → should match only between the two a
我怎样才能做到这一点?
试试这个模式:(a|b)(.*)\1
见正则表达式演示
解释
(...)
捕获的组(组 1)a|b
与 a 或 b 匹配。(.*)
与任何字符匹配零次或多次并将其捕获为第 2 组\1
与捕获的组匹配,如果组捕获“a”,\1 表示“a”。基本上,这意味着你匹配的开始在这个地方使用它。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句