首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用regex表达式匹配多行单词

如何使用regex表达式匹配多行单词
EN

Stack Overflow用户
提问于 2014-03-12 09:37:35
回答 1查看 1.3K关注 0票数 0

正如标题描述的那样,我想用regex表达式匹配多行单词,以"No“开头,以”e“结尾,.Here是下面的示例:

特殊指示

不是

特佛尔

R-c

我们

汤姆

er

签名

不可用

图尔

E

目录

客户详细资料1

地盘详情2

汤姆·汤姆销售B.V.德国分公司

动态带宽6

帐单详细资料7

我真正想要的是这样:

特殊指示

目录

客户详细资料1

地盘详情2

汤姆·汤姆销售B.V.德国分公司

动态带宽6

帐单详细资料7

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-12 09:45:44

您可以在多行单线选项中使用此模式:

代码语言:javascript
复制
@"^No\r?\n.*?^e\r?\n"

示例:

代码语言:javascript
复制
Regex rgx = new Regex(@"^No\r?\n.*?^e\r?\n",
      RegexOptions.Multiline|RegexOptions.Singleline);
string result = rgx.Replace(yourstr, "");

模式描述:

代码语言:javascript
复制
^        # anchor for the start of the line (because the multiline option is 
         # used, otherwise ^ is an anchor for the start of the string)
No
\r?\n    # an optional carriage return and a line feed
.*?      # all characters zero or more times (the dot can match newlines since 
         # the singleline option is used, the dot can't match newlines with the 
         # default behavior)
^        # anchor for the start of the line
e        #
\r?\n    # if you want to preserve the last CRLF you could replace this with $
         # ($ is an anchor for the end of the line in multiline mode, in default
         # mode, $ means "end of the string")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22347293

复制
相关文章

相似问题

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