Remove Data from string using Regex

Hi I have one Input String.
I want to delete everything inside the bracket.

Example -
Input String - John Smith - [ADMIN-01/31/2023 12:38:32 PM] and second and [third] - [ M] also - [ADMIN-01/31/2023 12:38:52 PM] and 4th - [TEST-02/21/2023 abc 01:37:23 AM]

Output - John Smith and second and also and 4th

Hi @madhabhazra0 ,

Could you try with the below Regex Expression :

Regex.Replace(Regex.Replace(yourInputString,"\-?\s\[.*?\]",""),"\s{2,}"," ")

Make sure the namespace System.Text.RegularExpressions is imported
image

1 Like

You can use regular expressions in UiPath to achieve this. Here’s an example of how to do it:

  1. Create a new variable of type string to hold the input string (let’s call it inputString).
  2. Use the “Assign” activity to set the value of a new variable (let’s call it outputString) to the result of the regular expression:
System.Text.RegularExpressions.Regex.Replace(inputString, "\[.*?\]", "")

This regular expression will match any text inside square brackets, including the brackets themselves, and replace it with an empty string.

  1. outputString now holds the desired result, which you can use in further steps of your automation.
2 Likes

Hello

Try this

System.Text.RegularExpressions.Regex.Replace(inputString, “[.*?]”, “”).trim.Replace(“-”,“”).trim

and store into output variable.

1 Like

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