Here is the pattern:
string str =
"+++++tom cruise 9:44AM something text here \r\n +++++mark taylor 9:21PM";
only string that starts with +++++
and ends with AM
or PM
should get selected. What is Regex.split or linq query pattern?
Try this regex:
@"[+]{5}[^\n]+[AP]M"
var str = "+++++tom cruise 9:44AM something text here \r\n +++++mark taylor 9:21PM";
var match = Regex.Match(str, @"[+]{5}[^\n]+[AP]M").Captures[0];
match.Value.Dump();
Output:
+++++tom cruise 9:44AM
or:
@"[+]{5}\D+\d{1,2}:\d{1,2}[AP]M
I recommend this regex. It will match until at find a hour on format xY:xY:AM/PM where Y is opcional. Test drive:
string str = "+++++tom cruise 9:44AM something text here \r\n +++++mark taylor 9:21PM";
foreach(Match match in Regex.Matches(str, @"[+]{5}\D+\d{1,2}:\d{1,2}[AP]M"))
Console.WriteLine(match.Value);
Output:
+++++tom cruise 9:44AM
+++++mark taylor 9:21PM
Talon almost got it, but you need a minimal capture, not greedy. Try
[+]{5}.*?(A|P)M
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With