简体   繁体   中英

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

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

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

Using a pattern to extract, then some LINQ to process:

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});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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