Create a regex to delete data in between

前端 未结 2 466
太阳男子
太阳男子 2021-01-25 20:15

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         


        
相关标签:
2条回答
  • 2021-01-25 20:42

    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:

    • Group 2 contains the email address.
    • Group 3 contains the text after the email address.
    • Group 4 contains the P.O. Box line.
    • Group 5 contains the Tel line.

    (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).

    0 讨论(0)
  • 2021-01-25 20:58
    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

    0 讨论(0)
提交回复
热议问题