regexsharepoint-2013phrasenintex-workflow

Regex for extracting text from .eml file


I need to write regex to get the following data from an email. The data to be phrased is first name, last name, phone number, email id, pin code, message etc, i am a newbie and am not much aware of REGEX, can anyone help me with it.

enter code hereContact Us

Title

Mr.

Last Name

S

First Name

Nitesh

Contact Us

By phone on: 0344 892 8979

E-Mail Address

niteshdsingh@gmail.com<mailto:niteshdsingh@gmail.com>

Phone Number

123456789

Postcode

421202

City

test

Message

test

Best Regards,


Solution

  • I don't think this regex can be regarded as a generic email parser... rather it will only work for the format that you have provided:

    Last\s+Name(?:\n)+((?: *\w+)+)|First\s+Name(?:\n)+((?: *\w+)+)|By phone on:((?: *\d+)+)|(?:E-Mail\s+Address(?:\n)+((?:(?: *\w+)+)@[^\.]+\.[^<]+))|(?:Phone Number(?:\n)+((?: *\w+)+))|(?:Postcode(?:\n)+((?: *\w+)+))|(?:Message(?:\n)+((?: *\w+)+))
    

    Regex 101 Demo

    Here in the following groups you get your desired data:

    Group 1.    Last Name
    Group 2.    First Name
    Group 3.    By phone on
    Group 4.    email
    Group 5.    Phone Number
    Group 6.    Postcode
    Group 7.    Message
    

    UPDATED AS PER THE OP COMMENT:

    (?:E-Mail\s+Address(?:\n)+((?:(?: *\w+)+)@[^\.]+\.[^<]+))|(?:Phone Number(?:\n)+((?: *\w+)+))|(?:Postcode(?:\n)+((?: *\w+)+))|(?:Message(?:\n)+((?: *\w+)+))|(?:City(?:\n)+((?: *\w+)+))
    

    Demo Two