I have a regex string with group names like this:
(?(regexstring1))|(?(regexstring2))|(?(regexstring3))
Now, how can I from UiPath get the match with group name G3 (which is sometimes the first, sometimes the second, sometimes the third hit)? Something like match(0).Groups(“G3”).Value (doesn’t work)?
Hi,
Can you share more specific sample such as Input string , regex pattern and output?
Regards,
Sorry, should have been
(?(regexstring1))|(?(regexstring2))|(?(regexstring3))
??? Some of my text is removed when I press Reply??? ,, and disappear!?!?!?!
(?(regexstring1))|(?(regexstring2))|(?(regexstring3))
less than G1 greater than, less than G2 greater than, less than G3 greater than
When written with symbols the above text disappears!?!?!?!
@Poul_Riis
it is recommended to use the format button </>
from the editor when sharing code snippets.
Maybe you are looking for the following: retrieve the information on which group name matched.
Variables:
Flow:
we init a Regex with the pattern and run the regex:
myRegex = new Regex(strPattern)
myMatches = myRegex.Matches(strText)
Then we do loop the matches and check for all non-empty group members the group name:
arrMatchedGroups =
(From t In m.Groups.Cast(Of Group).Select(Function (x,i) Tuple.Create(i, x)).Skip(1)
Where Not String.IsNullOrEmpty(t.Item2.Value)
Let n = myRegex.GroupNameFromNumber(t.Item1)
Select name=n).toArray
OR simplified:
(From gn In myRegex.GetGroupNames.Skip(1)
Where m.Groups(gn).Success
Select name=gn).toArray
Log:
Also, have a look here:
myMatches(0).Groups(myRegex.GroupNumberFromName("b")).Value
myMatches(0).Groups("b").Value
@Poul_Riis
As an alternate interpretation of your case. Get all group b matches
myRegex, myMatches used as described above
myMatches.Cast(Of Match).Where(Function (m) m.Groups("b").Success).toArray