Applying regEx correctly to variable

Hello!
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!
Thanks

In assign activity

variable=System.Text.RegularExpressions.Regex.Match(“inputString",“Regex”).Value

1 Like

Hi,

How about the following?

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

modified pattern a little.

Regards,

1 Like

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

Note : str variable type is System.String

@theEmailRobot

2 Likes

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.