Regex to get the value from brackets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 06:57 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 07:02 AM
Hello,
Try below code -
var reg = "12345(Aukland)";
var value = reg.match(/\(([^)]+)\)/)[1];
Regards,
Akshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 08:52 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 08:49 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 08:52 PM
Hi
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(')')));
}
Aman Kumar