[英]Simple Regex needed
I have text file 我有文字档
01:02:39.952 MC:My text with several lines
01:02:39.952
How I can catch all the text between 01:02:39.952 MC:
and 01:02:39.952
我如何捕获01:02:39.952 MC:
和01:02:39.952
之间的所有文本
I have a lot of line like this in my text file with this pattern, I want to catch all of them. 我在带有这种模式的文本文件中有很多这样的行,我想抓住所有这些行。
Assuming that your pattern is more general than exactly those numbers: 假设您的模式比这些数字更笼统:
Regex regexObj = new Regex(
@"
(?<= # Assert that the following can be matched before the current position:
\b # start of ""word""
\d{2}:\d{2}:\d{2}\.\d{3} # nn:nn:nn.nnn
\sMC: # <space>MC:
) # End of lookbehind assertion
.*? # Match any number of characters (as few as possible)...
(?= # ...until the following can be matched after the current position:
\b # start of word
\d{2}:\d{2}:\d{2}\.\d{3} # nn:nn:nn.nnn
\b # end of word
) # End of lookahead assertion",
RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
Match matchResult = regexObj.Match(subjectString);
while (matchResult.Success) {
resultList.Add(matchResult.Value);
matchResult = matchResult.NextMatch();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.