Regex to get the value from brackets

Nagesh5
Tera Contributor

Hello Team,

We have different values in one of the reference fields in particular table like below

12345(Aukland)

098765(namibia)

We need help to filter the values in the brackets only with the help of regex like below by removing all the values other than values in brackets

Aukland

Namibia

Post that we need to verify above values will be avialable in particuler table or not

Can anyone help on this

thanks,

nagesh

8 REPLIES 8

Community Alums
Not applicable

Hello,

Try below code -

var reg = "12345(Aukland)";
var value = reg.match(/\(([^)]+)\)/)[1];

 

Regards,

Akshay

Thanks for the feedback and it's not working in the below example.Can you help me with the below senarios as well becuase some times we have more than 2 names in glide list.

12345(Aukland),098765(namibia).

Muhammad Khan
Mega Sage
Mega Sage

Hi Nagesh,

 

Try the following script in the background script.

var str = '12345(Aukland),098765(namibia)';

var arr = str.split(',');

for(var i=0; i<arr.length; i++){
  gs.print(arr[i].match(/\((.*?)\)/)[1]);
}

 

Hopefully, this will help you to resolve your query.

Aman Kumar S
Kilo Patron

Hi @Nagesh 

You can follow below simple javascript functions, which you can also understand and adjust according to your requirements:

var txt = "12345(Aukland),098765(namibia)";
var txtArr = txt.split(',');

for(var i in txtArr){
    var str = txtArr[i];
    gs.info(str.substring(str.indexOf('(') + 1, str.lastIndexOf(')')));
}

Best Regards
Aman Kumar