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

The thing is that this also matches something like "Hello12345678901234567890123456789012World". Typically, you want to make sure that there are word boundaries around the Sys ID and also make sure the case does not matter with the "i" flag:

 

var regexp = /\b[0-9a-f]{32}\b/i 

 

I use a tool like RegExr: Learn, Build, & Test RegEx to test such Expressions.

 

Also, I can really recommend this resource: Regular Expressions :: Eloquent JavaScript


If this answer was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel