Regular Expression - Remove Part Of A String

I have a string in the variable “person”. E.G “John Smith JP606060D 01/01/2019 Male”

I want to remove all dates from the string. The date is different in each occurance of person.

I’ve tried using: RegEx.Replace(person.ToString.Trim,“^([0-2][0-9]|(3)[0-1])(/)(((0)[0-9])|((1)[0-2]))(/)\d{4}$”,“”)

but, this only removes the date if the string is “01/01/2019”, but not if it is within a larger string as per the example above

Can anyone assist please? Thanks.

Replace.xaml (7.6 KB)

Try this, see if it helps

You can use just this regex:
image
And the just use index needed for your case (written bellow words in my screen).

Test16.zip (26.9 KB)
I uploaded a file where the input string is “John Smith JP606060D 01/01/2019 Male” and the output string is “John Smith JP606060D Male”.
You can refer to it

1 Like

Thanks everyone. Managed to use @Vivek_Kumar code to get things working.

@Pablito Your code works for the example I gave, but sometimes there are multiple middle names.

@srdjan.suc What was the package for the first activity in your workflow? I can’t get it to load that activity.

1 Like

Ah damn, I need to stop using this BetaFeed.

My Dependencies are:

“dependencies”: {
“UiPath.Excel.Activities”: “[2.6.2]”,
“UiPath.Mail.Activities”: “[1.5.1]”,
“UiPath.System.Activities”: “[19.7.0]”,
“UiPath.UIAutomation.Activities”: “[19.7.0]”
},

Multiple middle names are not a problem :slight_smile:
This regex will mark any word in whole sentence so you can just combine indexes you want to use as a string like:

regex_output(0).ToString + regex_output(1).ToString + regex_output(3).ToString + regex_output(8).ToString etc.

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