Extracting date from using regex

Hi could any one please help on urgent basis.

  1. I want to extract the date after (xyz),whenever in the string “(xyz)” appears for the first time. i.e. 4 November 2009
  2. I want the account name mentioned just before “Migrated” i.e Advantage Silver account

Open Sole Student account (abc) 7 September 1999Converted to Graduate account (abc) 1 July 2002Converted to Student account (abc) 8 August 2002Converted to Advantage silver account (xyz) 4 November 2009Migrated to Select gold account (xyz) 24 July 2015

Thanks in advance.

@Amrita Can you elaborate more with input string and expected output string

Input String= “Open Sole Student account (abc) 7 September 1999Converted to Graduate account (abc) 1 July 2002Converted to Student account (abc) 8 August 2002Converted to Advantage silver account (xyz) 4 November 2009Migrated to Select gold account (xyz) 24 July 2015”

Output 1:extract the date after (xyz),whenever in the string “(xyz)” appears for the first time. i.e. 4 November 2009

Output 2: account name mentioned just before “Migrated” i.e Advantage Silver account

@Amrita For date use This Regex

I cannot hard code Migrated word since it is possible that there is some other text

Hi Amrita,

Try this Regex

For Date : (?<=[(]xyz[)]) (\d{0,2} [A-Za-z]+(?=\s) \d{4})

For Account Number : (?<=to)[A-Za-z ]+(?=[(]xyz[)] )

When you use these regex you will be getting multiple matches, so you have to take the first match and break the loop, if you don’t want that you can try this

For Account Number :

  1. First Use the above regex for date store in some variable
  2. Use the above variable in Account number regex where i have hardcoded the date as “4 November 2009” and you will get exactly “Advantage silver account”

(?<=to)[A-Za-z ]+(?=[(]xyz[)]\s+4 November 2009)

Try this and let me know if it works.

How to find the date in the email body (Now this date is Wednesday, February 20, 2019 2:13 PM
Like: Email Contents is

Hi,

XYZ has updated ticket 101614 in “Project name” queue. Kindly review the ticket:


Update

Note:
Will be resolved on Monday.

This is alert Wednesday, February 20, 2019 2:13 PM

The ticket can be accessed using the following link: