首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分隔符之间的C#正则表达式替换

分隔符之间的C#正则表达式替换
EN

Stack Overflow用户
提问于 2011-11-04 05:43:57
回答 1查看 206关注 0票数 0

我想用另一个集合替换标记11=和~之间的所有字符。示例11=1234~应替换为11=56789~。第一个分隔符应该是以单词为界的,即111=不应该匹配

EN

回答 1

Stack Overflow用户

发布于 2011-11-04 05:56:48

好吧,你已经回答了你的问题:

代码语言:javascript
复制
resultString = Regex.Replace(subjectString, @"(?<=\b11=).*?(?=~)", "56789");

这是.NET,你可以把它翻译成其他口味/引擎。

说明:

代码语言:javascript
复制
@"
(?<=      # 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
)
"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8002292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档