所以我在下面有一个文本块,
#start
Line 1
Line 2
Line 3
#end
*--Similar blocks-*
我用这个
Regex.Matches(text,@"#start(.*?)#end",RegexOptions.Multiline)
上面的代码的正则表达式。
问题是,当我尝试通过Notepad ++查找选项匹配此Regex时,它可以工作,但通过C#Regex.Matches函数,则失败。
我不知道到底是什么问题。但是希望大家能帮助我!:)
您需要一个Singleline
正则表达式模式。尝试使用此代码,它将在#start
和之间打印文本#end
var input = @"#start
Line 1
Line 2
Line 3
#end
#start
Line 4
Line 5
Line 6
#end";
var reges = new Regex("#start(.*?)#end", RegexOptions.Singleline);
var blocks = reges.Matches(input).Cast<Match>();
foreach (var block in blocks)
Console.WriteLine(block.Groups[1].Value);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句