I want to extract the date after (xyz),whenever in the string “(xyz)” appears for the first time. i.e. 4 November 2009
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
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
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 :
First Use the above regex for date store in some variable
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”