I'm working on extracting specif string set after matching a pattern but results are not as expected. Instead of first occurrence starting from top of the text file the function picks very last occurrence.
Function:
[\n\r].*Sent:\s*([^\n\r]*)
Sample text:
From: Y Sent: Monday, November 6, 2018 6:38 AM To: X
BLA BLA
Thank you,
From: X Sent: Monday, November 5, 2018 8:38 AM To: Y
Hi Y BLA
Thanks,
Expected results:
Monday, November 6, 2018 6:38 AM
Curently returns:
Monday, November 5, 2018 8:38 AM
You're close. Try this:
This looks for
'Sent'
, acolon
, an optional WhiteSpace
, then it createsGroup 1
, matching any number ofany char
until it reaches a WhiteSpace
and 'To:
'.If you set the global flag, it will match both dates, otherwise just the first.
The date will be in
Group 1
.