Regex method for automation

Hi All,
I need to get employee ID and Action values using regex method and our employee ID would be mix of 5 digit Numeric and char , How to write regex command for this , can anyone help on this .

e.g “Employee ID 123TY”, " Action Hire "

Try this
To get employee id
System.Text.RegularExpressions.Regex.Match(txtStr,“Employee ID (\w{5})”).Groups(1).Value

Does action value always start with keyword action? or is it always after employee id?

Can you put an example of your input and your desired output?

Hi @Krishnakumar_Vasudevan

For employe id you can try this way

System.Text.RegularExpression.Regex.Match(“Employee ID 123TY”,“(?<=Employee ID[\s*])[A-Z0-9]{5}”).Value

For the reference you can see the screen shot

Hi @Krishnakumar_Vasudevan

If your employee I’d is like this 12345A five numbers with one character.

Then use the below regular expression
(\d{5}\w{1})

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((\d{5}\w{1}))”)

image

If your Input is like this Employee ID 123TY as you given in the query.

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((?<=Employee ID\s+)\d+\w+)”)

Hope it helps!!

Hi @Krishnakumar_Vasudevan

strinput: Employee ID 12345TZY
output: System.Text.RegularExpressions.Regex.Match(strinput,"[A-Z0-9]+[0-9A-Z]+\n").Value

Both strinput and output variables are of datatype System.String.

Hope it helps!!

@Krishnakumar_Vasudevan

  1. For EmpId you can use (?<=Employee ID\s*)\d{4}[A-Za-z]

  1. For Action (?<=Action\s*)[A-Za-z]+

Implementation System.Text.RegularExpressions.Regex.Match(str,"Pattern").Value

Hope this helps

Cheers

Hi @Krishnakumar_Vasudevan

(?<=Employee ID )\d+\w+

image

(?<=Action )\w+

image

Hope it helps!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.