带缩进的c#正则表达式匹配模式
本文关键字:模式 正则表达式 缩进 | 更新日期: 2023-09-27 18:08:21
我有一个文本文件,我想匹配文本文件中出现10次的3行。我的问题是用缩进匹配这3行,第三行可以是任何单词
线的例子:
Then something something
Follow by something found
Something something
这是我到目前为止所尝试的:
string pattern = @"'s's's'sThen(['s'S]*)found('n|'r|'r'n)('s's's's's's)(.*)";
match = Regex.Match(input, pattern, RegexOptions.Multiline);
结果给了我500个匹配,这不是我想要的。
我对所需的格式进行了大胆的猜测,但是您可以尝试这样做:
var text = @" Then something something
Follow by something found
Something something
";
var pattern = @"[ ]{4}Then['w's]+('r|'n|'r'n)[ ]{6}['w's]+found('r|'n|'r'n)[ ]{6}['w's]+('r|'n|'r'n)";
var match = Regex.Match(text, pattern, RegexOptions.Multiline)