Regex 2nd match

Hi,

In my automation I have a Regex like :
System.Text.RegularExpressions.Regex.Match(EmailBody,“(?<=Role : ).+”).Value

it works perfectly well, but there are some changes in automation and I have 3 places now like “Role :”.

Is it possible to have a list of there 3 regexes or tell regex to get the 2nd or 3rd one?

Thanks!

@wenar58700

Use Matches instead of Match to get all values from all the matches.

   System.Text.RegularExpressions.Regex.Matches(EmailBody,"(?<=Role : ).+")

The above expression will give you IEumberable of matches.

ok, and assign to this list of IEnumerable?

Hi @wenar58700 ,

Could you provide us an Example of your Input Data ?

Is it that you have Multiple Role Values ? As you mentioned is it 3 of them only or does the Count of the Values Differ ?

@wenar58700

  1. Create one variable of type Array of string and pass above expression to it. Let’s say arrString.

  2. And then use For Each loop activity.

          For Each item in arrString
               print item
    

Hi,

sure:

1 Specialist: 123

Role : 234

Title : 345

Service : 456

Role : 567

Title : 678

2 Specialist: 789

Role : 890

Title : 009

Hi,

.value is not a member of matches. I don’t know what to choose here.

@wenar58700 , Try using the Below :

System.Text.RegularExpressions.Regex.Matches(EmailBody,"(?<=Role : ).+")(0).Value

Notice (0) is being used to access the first Matched Value.

You could try accessing other repeated time values by using (1),(2),…

We do this accessing when we know the Definite number of times the Role values are present for an Input.

I get value of type string cannot be converted to 1-dimensional array of string.

The variable I have is String

@wenar58700 , If you want to Store all the values in a String[], then you can use the below Expression :

System.Text.RegularExpressions.Regex.Matches(EmailBody,"(?<=Role : ).+").Cast(Of Match).Select(Function(x)x.value.ToString).ToArray