Applying regEx correctly to variable

I’m trying to use regex to trim a string to a maximum of 10 digits. This is the regex I have and it seems to work fine “(\d{0,10})(?!.*\d)”.
I’m not sure how to apply the regex using assign activity and alter the variable to a new one.
Ex. myVar = myVar.(applyRegExHereSomehow)
Any suggestions would be helpful, I’m also aware you can invoke code and do it that way as well but the examples I have found I have not been able to replicate successfully.

I’m quite new to UiPath so bear with me!

In assign activity


1 Like


How about the following?

myVar = System.Text.RegularExpressions.Regex.Match(myVar,"\d{0,10}(?!\d)").Value

modified pattern a little.


1 Like

Str =System.Text.RegularExpressions.Regex.Match(“YourInput",“Regexpattern”).Value

Note : str variable type is System.String



Yes this worked like a charm! I decided to use the regex altered by @Yoichi, I might have been bad at googling because this was the first I heard of the System.Text… solution. I had just found Regex.Match solutions before.
Anyways thanks you lot! You’re magicians!

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