正如标题描述的那样,我想用regex表达式匹配多行单词,以"No“开头,以”e“结尾,.Here是下面的示例:
特殊指示
不是
特佛尔
R-c
我们
汤姆
er
签名
不可用
图尔
E
目录
客户详细资料1
地盘详情2
汤姆·汤姆销售B.V.德国分公司
动态带宽6
帐单详细资料7
我真正想要的是这样:
特殊指示
目录
客户详细资料1
地盘详情2
汤姆·汤姆销售B.V.德国分公司
动态带宽6
帐单详细资料7
任何帮助都将不胜感激。
发布于 2014-03-12 09:45:44
您可以在多行和单线选项中使用此模式:
@"^No\r?\n.*?^e\r?\n"示例:
Regex rgx = new Regex(@"^No\r?\n.*?^e\r?\n",
RegexOptions.Multiline|RegexOptions.Singleline);
string result = rgx.Replace(yourstr, "");模式描述:
^ # 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")https://stackoverflow.com/questions/22347293
复制相似问题