简体   繁体   English

正则表达式会选择所有内容,直到下一场比赛为止,包括换行

[英]Regex select everything up until next match including new lines

Im trying to capture the conversation below but the regex expression only capture a single line, I want it to capture the entire phrase said by anyone up until the next person says anything else. 我试图捕获下面的对话,但是正则表达式仅捕获一行,我希望它捕获任何人说的整个短语,直到下一个人说其他任何话。 If I use the /s setting, the '.+' will capture everything until the end of the file not until the next match 如果我使用/ s设置,则'。+'将捕获所有内容,直到文件结尾,直到下一个匹配为止

Im new to the regular expressions, sorry for any bad explanation 我是正则表达式的新手,对不起任何不好的解释

This is what Ive got so far 这就是我到目前为止

The regex expression: 正则表达式:

/([0-9]{2}\/[0-9]{2}\/[0-9]{2} [0-9]{2}\:[0-9]{2}\:[0-9]{2}: (.+):) (.+)/

What I want 我想要的是

Regex101 Fiddle Regex101小提琴

I going to use use both \\2 and \\3 to capture who said and the phrase said inside a for loop so I can text mine it 我将同时使用\\ 2和\\ 3来捕获谁说过的短语以及在for循环中说的短语,以便我可以通过文本进行挖掘

Using a pattern to extract, then some LINQ to process: 使用模式提取,然后使用一些LINQ进行处理:

var pattern = "^[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}: (.+?): ((?:[^/]+(?:\n|$))+)";

var data = Regex.Matches(src, pattern, RegexOptions.Multiline).Cast<Match>().Select(m => new { who = m.Groups[1].Value, text = m.Groups[2].Value});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM