Keep value inside ()

Hello!

I am wondering if there is a way to trim and keep values inside ().
For example, I am scraping a text and getting the value “John Evans (Jonny)”, and I would like to create an assign value or similar to trim it to only keep the “Jonny” value.
Does it have to be turned into a datatable and then use Filter Datatable activity or is it an easier way of doing it?
Thanks in advance!

Best regards
Robert

@Robert_Wennberg
such tasks are done with RegEx

a play with regex101.com
grafik

returns following groups:
grafik

so group2 can be trimmed.

Just to give a starter help, feel free to adopt and to enhance

2 Likes

You can use the Split and Substring method to achieve that
Variable_name.Split(" "c)(2).Substring(1,5)

Thanks

3 Likes

@Robert_Wennberg You can maybe use the String Split operation in this way as well :

Split(Split(“John Evans (Jonny)”,"(")(1),")")(0).Trim

4 Likes

Hi @Robert_Wennberg

Below regex will give the value within Bracs() everytime.

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

4 Likes

@supermanPunch

Thank you for always giving easy to understand and correct solutions.
In this case, the names I get are dynamic, so by just switching out the “John Evans” part to my variable, I managed to trim the text just the way I wanted!

@ppr

Thank you for your quick and informative response.
However, I am not yet familiar with RegEx but I would like to understand more of it since it seems to be fairly used together with UiPath… Is there any place you could recommend to study it for beginners? Sorry for the inconvenience

Refer this post

Thanks

1 Like

@supermanPunch

I also have a followup question regarding the trimming. Is there a way to remove text and leave special characters such as Japanese kanji? Something like this:

Example: "Ryosuke Maeda 前田 凌佑 "
Expected result: “前田 凌佑”

The name will be dynamic.

Thanks!

@Robert_Wennberg
along with the linked post from @Steven_McKeering
playing in https://regex101.com/ is a good first stop to start and grow

3 Likes

@ppr

Got it, thank you very much!

1 Like

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