如何找到与另一个字符串最接近的匹配字符串
所以例如
string1:val1 ... string1:val2 .... string2:val3 ...
应该捕获最接近string2的string1,这将是" string1:val2"
string1可以出现任意次。
字符之间可以是任何
答案 0 :(得分:2)
最简单的方法就像(?s)"title":(?:(?!"title":).)*?"value":".*?"
(?s) # Dot-all modifier
"title": # Literal 'title'
(?: # Group start
(?! "title": ) # Negative assertion, not 'title' ahead
. # Ok, grab this chakracter
)*? # Group end, do 0 to many times
"value":" .*? " # Until 'value' is found
输出
** Grp 0 - ( pos 73 , len 39 )
"title":"text2" asjdsjsd "value":"val1"