Get SysIDs! out of String (REGEX)

Meloper
Kilo Sage

Hi, 

i get the Value of the Reference Field of the sys_dictionary Table

var ref_qual = gr_dic.getDisplayValue("reference_qual");

or

gr_dic.getValue("reference_qual")

 

With both i get 

typeLIKE5f230a666fdd6100106de5ec5d3ee493^ORtypeLIKE1bff3b1493030200ea933007f67ffb6d^EQ

 

can someone pleas help me to get the SYSids of that String with a REGEX.

The Regey shoul also work, if there is 1 SYSid or 300 🙂

 

Thank you

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi,

As in your case there will be multiple sys_ids in string, please use below regex pattern.

/[a-f0-9]{32}/g

Example :
var str="typeLIKE5f230a666fdd6100106de5ec5d3ee493^ORtypeLIKE1bff3b1493030200ea933007f67ffb6d^EQ";
gs.print(str.match(/[a-f0-9]{32}/g));

Output :

find_real_file.png

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

 

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi @Meloper ,

var regexp = /[0-9a-f]{32}/;

var out = (current.u_text.match(regexp));

If you are looking for a solution to get a sys_id from a whole sentence, it is highly unlikely that the sentence will randomly have 32 hexadecimal characters in it - that's what makes the sys_id so easy to identify. That same pattern will work. It just says look for 32 consecutive characters as long as they are 0 through 9 or a-f. If it doesn't match that, I don't care.

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Abhijit4
Mega Sage

Hi,

You can use below regex pattern to extract sys_id's from given string. If it has multiple sys_ids, it returns all separated by comma,

var str="typeLIKE5f230a666fdd6100106de5ec5d3ee493^ORtypeLIKE1bff3b1493030200ea933007f67ffb6d^EQ";
gs.print(str.match(/[a-f0-9]{33}/gi));

Output :

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Abhijit4
Mega Sage

Hi,

As in your case there will be multiple sys_ids in string, please use below regex pattern.

/[a-f0-9]{32}/g

Example :
var str="typeLIKE5f230a666fdd6100106de5ec5d3ee493^ORtypeLIKE1bff3b1493030200ea933007f67ffb6d^EQ";
gs.print(str.match(/[a-f0-9]{32}/g));

Output :

find_real_file.png

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

 

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Thank you