我想用另一个集合替换标记11=和~之间的所有字符。示例11=1234~应替换为11=56789~。第一个分隔符应该是以单词为界的,即111=不应该匹配
发布于 2011-11-04 05:56:48
好吧,你已经回答了你的问题:
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
)
"https://stackoverflow.com/questions/8002292
复制相似问题