Extract text between brackets

Hi Guys,

I need to extract text present in the bracket from the whole string
The string1 is: ELIGIBLE - PREMIUM TAB (PREMTAB_HCC)
And the string2 is : ELIGIBLE - PREMIUMTAB (PREMTAB_HCC) | 2 Year | PREMTAB_HCC

I want to match only the text present in bracket if it is same or not i.e. (PREMTAB_HCC)

Please help

1 Like

You’re going to need to use regex to look for a string that fits the form of ( stuff ) then trim off the () and return whatever is left.

You can probably harvest the code out of this:

Hi @somya177,

You can assign String_var=System.Text.RegularExpressions.Regex.Match(Your_String,"\(.*\)").ToString to extract the value inside the parenthesis.

Warm Regards,
Nimin

2 Likes

Hi @somya177,

You can use this regEx
RegExMatch - should be a Match variable
RegExMatch = System.Text.RegularExpressions.Regex.Match([String],“(?!.+()(?.+))”)

to get the value with the regEx group of “bracket”, use this on your assign activity - RegExMatch.Groups(“bracket”).Value

Regards,
Jeven

2 Likes

Hi Nimin

Just for a clarification, The regex which u mentioned will give the output with the braces.
How to get the value alone without braces? How to modify the regex value for the same ?

Hi @Pradeep.Robot,

You can use the regex (?<=\().*?(?=\)) to get the values inside the braces. Please check this out. :slightly_smiling_face:

Warm Regards,
Nimin

9 Likes

Hi,

This will work for you: try it with message box.
System.Text.RegularExpressions.Regex.Match(“I am from (Pune) Maharashtra”,“(?<=().*?(?=))”).ToString
Output: Pune

Thanks,
Swapnil

But if we use this Expression the value comes along with parentheses…what to do if we want to get the values only inside the angular parentheses!?

If an example looks like this…
"professor,mario(Lacasadepapel)"Tokyo
< BERLIN.OSLO@Royalmint.com >

I need to get the data only inside the angel <> brackets…any suggestions/solutions???

Might be helpful, as I find many working with Regex not knowing about this:

You can use Regex.Matches instead of Regex.Match to get a collection of all matches rather than only the first match.

Can you explain how it works