我们得到了这样的内容:
state 1rd court house, state state 2nd court house
我们想要的是state xxx court house
我们试试lookahead / lookbehind像这样:
(?=state).*?(?<=court house)
但是这个正则表达式提取aab
就像内容一样ab
种内容
如何从ab
aab
表示start with something, but the capture content do not contains it
更新
抱歉描述不佳
我想要匹配的是
state 1rd court house
和state 2nd court house
而不匹配state state 2nd court house
?这意味着如果
state state 2nd court house
我想提取后方state 2nd court house
,请忽略内容中出现的第一个state
。
答案 0 :(得分:0)
如果我理解正确,你只想在法庭上捕捉一切,包括&#34;法院&#34;。
正则表达式
state(?<whatYouWant> [0-9].*?court house)*
测试字符串
state 1st court house, state state 2nd court house
匹配1:
state 1st court house
小组whatYouWant
:1st court house
匹配2:state 1st court house
小组whatYouWant
:2nd court house
我认为当你点击数字时,回头会停止:&#34; 1&#34;,&#34; 2&#34;。如果我的假设是错误的,请将打破正则表达式的数据发给我。