Remove the Parenthesis and keep with contents within

Hello All,
This is my first post here in the forum and relatively new to UiPath although I’ve been a vivid user of the forum :wink:

This is my doubt,

  1. I have a string variable (it might be a combination of alphanumeric with special characters - for ex : “#H3ll0&@Ll26”)
    And this above mentioned string will be getting in the below fashion
    Type 1 - (#H3ll0&@Ll26):
    Type 2 - ((#H3ll0&@Ll26)):
    Type 3 - (#H3ll0(&)@Ll26):

So what I am looking for is, when I get a string like Type 1 - I need to manipulate it in such a way I should remove the open and closing parenthesis and make the string look like #H3ll0&@Ll26

For Type 2 - it should look like #H3ll0&@Ll26

For Type 3 - #H3ll0(&)@Ll26 (here the open & closing parenthesis inside the string should remain as such.

I’ve used the following techniques so far
a. regex - (?<=()[A-Za-z0-9!#$%^&_-@ ](?<!)) = when I use this, if there is a second open and closing parenthesis, it will create one null match which I don’t need.
b. remove & use substring

but these options not really helps my needs !

Can somebody please help me out with getting a proper solution ?

Thanks in advance :slight_smile:

Hi,

Is colon at the end of the string content of string?

If so, the following will work.

yourString.TrimEnd(":"c).TrimEnd(")"c).TrimStart("("c)

If not, can you try the following?

yourString.TrimEnd(")"c).TrimStart("("c)

Regards,

grafik

Thank You so very much for the solution !

I would need both your resolutions because sometimes there might be a “special character” after the parenthesis … I have utilized both your solution into my flow.
It worked as expected :smiley:

It would be extremely helpful If I could get a solution for the below scenarios
For the below one’s I have to keep the parenthesis

  1. Test(12)Try) - for this one, all the open and close parenthesis needs to kept in place.
  2. Test(12Provide
  3. (Test)12 Provide

for all these 3 types, need to keep them and not replace or remove the parenthesis

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString.TrimEnd(":"c),"^\(+(.+?)\)+$","$1")

Regards,

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