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

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

1 Like

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 @kk.virags,

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

Warm Regards,
Nimin

2 Likes