javascript - regular expressions- not including a character -
i want capture value name query string regular expression; have done folowing:
/name=(.*)/g example: ?name=foo&bar=baz
but grabs string end; know ^
used not; not figure out right syntax.
thanks
if want use regex can use non greedy operator this:
name=(.*?)&
btw, can regex cover more cases:
name=(.*?)(?:&|$)
javascript code:
var re = /name=(.*?)(?:&|$)/gm; var str = 'example: ?name=foo&bar=baz\nexample: ?name=foo\nexample: ?bar=baz&name=foo'; var m; while ((m = re.exec(str)) !== null) { if (m.index === re.lastindex) { re.lastindex++; } // view result using m-variable. // eg m[0] etc. }
Comments
Post a Comment