Regular expression to extract a sys_id

oharel
Kilo Sage

Hi,

I need to extract the sys_id from a string:

bla bla bla name="sys_id" value="SYSID"

Example: parameter name="sys_id" value="bd3192d73739b200166ed2e843990e40"

So I have this:

var regexp = /name="sys_id" value="([^{32,}$])/;

var out = (current.u_text.match(regexp))[1];

gs.addInfoMessage('out is ' + out);

The infoMessage shows: out is b

The sys_id is bd3192d73739b200166ed2e843990e40, so I get the first character.

Also tried: var regexp = /name="sys_id" value="([^\w{32,}$])/; and all kind of combinations with [a-z0-9].

Your thoughts are welcome.

Harel

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Have you tried the simple approach?



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


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

Have you tried the simple approach?



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


Hi Chuck,


Thanks for the reply.


I tried that as well. Same output: out is b .


When I test in a regular expression tester, both your string and mine \w{32} work.


I'm baffled.


Also adding bernyalvarado who helped me a long time ago   with the same subject.


Hi Chuck,


So in the end, your suggestion did the trick. I ignored the string that comes before the sys_id.


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


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



Out of curiosity (and for future needs), what should I use if I want to extract a string (like a sys_id) from another string (like a whole sentence)?



harel


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.