Regex help to add "or" condition

Hi Team,
@lakshman
Need regex help to add “or” condition in below regex code:

status code=“EL”+ Regex.Match(EmailID, “(?<=EL)([0-9]{2})-”).ToString

Agent Status=EmailID.Substring(EmailID.LastIndexOf(statusCode))

The above code will write the column starting from “EL”,but i have new condition also from “P”
Can any one help to add or condition,It should be like ,write the column starting from "EL or “P”.
With the same code am getting error as :
slight_smile:image

Appreciate your help @lakshman

1 Like

@RajeshT

Yes you can write OR condition in REGEX and for this use “|”.

1 Like

Hi @lakshman
Will the below code am still getting same error:

status code=“EL|P”+ Regex.Match(EmailID, “(?<=EL|P)([0-9]{2})-”).ToString

@RajeshT

Why you are writing it here also.

Could you please show me some sample input data and so that i can check my end will let you know.

Hi @lakshman @sarathi125
image

Regex Text File to Excel.xaml (67.4 KB)

@RajeshT

Do you want to the text till hypen “-” or want full text ?

@lakshman
Full text ,the above code writes from text file to excel file,I need to capture date whole from EL or P

@RajeshT

Please try below Regular expression and you can test it here. I tried the same and it’s working fine. Please find the attached screenshot.

         ^(EL|P)\w*-\w*

1 Like

Hi @lakshman @sarathi125
Based on your inputs am bit confused where to update this code as per my code.
Appreciate your help!

@RajeshT

You have to replace this regular expression with one i provided in my previous post.

Hi @lakshman
UpdateD as below,but still getting same error(Run time execution error) and error message i mentioned is exactly like this " P1234-ab34-AGFRJU SECURITY NUMBER-NRIC not matched with DOB"
“EL”+Regex.Match(EmailID, “^(EL|P)\w*-\w*”).ToString

image

Hi @lakshman @sarathi125
I have tried below code:
1)Regex.Match(EmailID, “(?<=EL)([0-9]{2})|(?<=P)([0-9]{4})-”).ToString
Its copied all lines but didnt copied EL and P characters.
image
2)“EL|P”+Regex.Match(EmailID, “(?<=EL)([0-9]{2})|(?<=P)([0-9]{4})-”).ToString
With this code triggered below error:

image

@RajeshT

Here, replace this string (?<=EL) with ^(EL) and (?<=P) with and then check it once.

1 Like

Hi @lakshman ,

Its not copying as expected:
Its copied only last characters,before characters moved to before column.

Regex.Match(EmailID, “^(EL)([0-9]{2})|^$([0-9]{4})-”).ToString
image

@RajeshT

Don’t know where it’s going wrong.

The one i provided in the my previous posts and it’s identifying all the text and provided screenshot also. Check it same.

1 Like

Hi @sarathi125 ,


I have some changes required related to this topic,could you please help out here.

1 Like

Appreciate your help! @sarathi125

@RajeshT,

Let me know what needs to be done.

Thank you for the response @sarathi125
Link posted to you is converting text file to excel,and last column copied if the text data starts with “ELXX” with below code.

status code=“EL”+ Regex.Match(EmailID, “(?<=EL)([0-9]{2})-”).ToString
Agent Status=EmailID.Substring(EmailID.LastIndexOf(statusCode))
Need a change if last column should copy if the text data starts with “ELXX” or "PXXX"with below code.
This was the change:
imageRegex Text File to Excel.xaml (67.4 KB)