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=(.*?)(?:&|$) 

working demo

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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -