I am having the below given data
Mr. SIM Kamsath, Vice President & Branch Manager
Tel: +855 (0)12 922 660, +855 (0)15 900 269
E-mail: getemail(\'acledabank.c
Your description is not very clear what you want for the first entry, where E-mail line is not available. I assume you don't want to extract anything from the first entry.
E-mail: getemail\('([^']*)','[^']*'\)([^@]*@\1)(.+)?\r?\n(?:(P.O. .*)\r?\n)?(Tel: .*)?
Demo on regex101 (I wrote the pattern to make it compatible with even JavaScript).
High level break down of the regex:
E-mail: getemail\('([^']*)','[^']*'\)([^@]*@\1)(.+)?\r?\n
matches the email line, and use the content from the argument to getemail
as hint to separate the email from the text that comes after. I assume there is no percentage escape in the string literal of getemail
.
(?:(P.O. .*)\r?\n)?
matches optional P.O. Box line
(Tel: .*)?
matches optional Tel line.
Capturing groups:
(I wrote group 3 as (.+)?
to make the group return null
/undefined
when nothing follows the email address, instead of (.*)
which will return an empty string).
E-mail:(?=(?:(?!E-mail)[\s\S])*P.O. Box)\s\S*\.([\s\S]*?)(?=Fax)
Try this.Grab the capture.See demo.
https://regex101.com/r/rU8yP6/15