regexp lookbehind - Invalid quantifier "?" - Any idea?

david_legrand
Kilo Sage

Hi everyone,

 

I'm trying to make a regexp and the lookbehind seems to not work. Any idea?

 

var resolution = 'Servername: AZSXCD123DERFC' + '\n' + 'IP: 123.45.67.89';
gs.log('::'+ resolution.match(/(?<=servername:\s*)[^\n\r\t\v]+/i) + '::');

Evaluator: org.mozilla.javascript.EcmaError: Invalid quantifier ?
   Caused by error in script at line -1

but

var resolution = 'Servername: AZSXCD123DERFC' + '\n' + 'IP: 123.45.67.89';
gs.log('::'+ resolution.match(/servername:\s*[^\n\r\t\v]+/i).toString().split(' ')[1] + '::');

*** Script: ::AZSXCD123DERFC::

 

And obviously, I would like to not use the split function to have a secured way.

 

Regards,

1 ACCEPTED SOLUTION

justin_drysdale
Mega Guru

Regex! My love language!   Kidding! From what I understand, there is no look behind in javascript's regex implementation.



javascript regex - look behind alternative? - Stack Overflow


View solution in original post

2 REPLIES 2

justin_drysdale
Mega Guru

Regex! My love language!   Kidding! From what I understand, there is no look behind in javascript's regex implementation.



javascript regex - look behind alternative? - Stack Overflow


And in fact my lookbehind was wrong as well because I had (?<=servername:\s*), in lookbehind, we can only match a "predefined number of characters" (so no * or +...)