Get string value between a string and a single character

ceraulo
Mega Guru

Hello!

 

I am working on a script to get the value between a string and a character. The sample is:

 

Name: firlas (Last Name, First Name)

 

The requirement is to get the value of "firlas". I tried creating a regex but it won't accept the character "(".  

 

var regex = /(?:Name: )(.*)(?:()/g;

 

Please help!

 

Thank you.

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @ceraulo ,

are you expecting only 'firlas' text from it. If yes try below

var name='Name: firlas (Last Name, First Name)';
var val=name.split(' (');
gs.info(val[0]);
var finalname=val[0].split('Name: ')
gs.info(finalname[1]);

Screenshot (703).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

2 REPLIES 2

Pavankumar_1
Mega Patron

Hi @ceraulo ,

are you expecting only 'firlas' text from it. If yes try below

var name='Name: firlas (Last Name, First Name)';
var val=name.split(' (');
gs.info(val[0]);
var finalname=val[0].split('Name: ')
gs.info(finalname[1]);

Screenshot (703).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

ceraulo
Mega Guru

This works! Thank you.