Using Regex to extract dynamic numbers

Is it possible to use both a regex and a variable in a selector? For instance, I am doing an automation that iterates through some selects, and then queries the database and every time it returns a string like this which gives the number of results:
image
I was able to use a regex to get the selector to work with the dynamic number but what I wanted to do was use this variable numResults to extract that for later use like this…
2022-05-03 (2)
Is this possible or do I need to use a get text to get the string, and then use matches or an assign or something to extract the number by parsing the string? I have the default value of the variable numResults set to the regex (\d+) but it just prints out the \d and not the actual number that I need. Is this not how the selector variables work?

Variables in selectors are used as input only. UiPath won’t modify it with the value it’s matching.

So go with your plan b. Get text and use Regex.Match() to get the number.

1 Like

that’s a shame, it would be a cool feature, but that you for your quick response!

Hi @Stephanie_Rimel,

If my understanding is correct, numResults should hold the integer values from the string “Your Search Produced 13 Results”, then try this method.

  1. Use a get text activity to get the text from the screen and save it in a string variable.
  2. In another string variable assign this expression,
    numResults = System.Text.RegularExpressions.Regex.Match(GetTextVar,"\d+").Value
  3. pass this numResults variable to the selector, and you will get the desired result.

Regards,
@90s_Developer

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