我想用另一组替换标签11 =和〜之间的所有字符。例11 = 1234~应替换为11 = 56789~。第一个分隔符应该是单词有界,意思是,111 =不应该是匹配
答案 0 :(得分:1)
你已经回答了你的问题:
resultString = Regex.Replace(subjectString, @"(?<=\b11=).*?(?=~)", "56789");
这是.NET,您可以将其转换为其他版本/引擎。
<强>解释强>
@"
(?<= # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
\b # Assert position at a word boundary
11= # Match the characters “11=” literally
)
. # Match any single character that is not a line break character
*? # Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
~ # Match the character “~” literally
)
"