Extract each text between parentheses

Hi,

I’m unable to extract each text between parentheses, below is example for all the possibilities that might happened:

String1 : “(AAA)-(P)+(QQ)”
result1 : AAA P QQ
__
String2 : “((M)-(XX))+(YY)”
result2 : M XX YY
__
String3 : “(AAA)”
result3 : AAA

Could any one help me to find one Regex that match all these examples.

Thank you

@malak_s

You can use Regex for this scenario

Check below for your reference

sampleString = YourString

use Assign sampleString = System.Text.RegularExpressions.Regex.Replace(sampleString,"[(]|[)]","")

This will trim down the () brackets

use Assign sampleString = System.Text.RegularExpressions.Regex.Replace(sampleString,"[-]|[+)]"," ")

This will search for - and + and replace with space

Hope this may help you

Thanks

1 Like

Thank you very much for your help, but what I need is to use regex.matches instead of replace, so for example1 after extracting I will loop through AAA,P, QQ .

@malak_s

You can loop by split

Assign a string variable and use sampleString.Split(" ")

The use For Each activity to loop

Hope this may help you

Thanks

Thank you, I think I will do that

1 Like

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