JavaScript regex \G + offset equivalent -
is there equivalent of \g
in javascript regular expressions? need match pattern @ exact offset. setting g
flag , .lastindex
searches forward given index, won't match @ offset exactly.
xregexp has y
modifier might i'm looking for, doesn't appear work in node/v8.
i think thing can set .lastindex
starting point, try match .exec()
, , if match check updated value of .lastindex
. if it's equal starting position plus length of match result, match began wanted.
so:
var re = /banana/g; re.lastindex = 6; var mr = re.exec("hello banana"); if (mr[0].length + 6 === re.lastindex) alert("good banana");
i never claim "good" way of doing things, it's possibility know of.
Comments
Post a Comment