regex - Finding inner matches using Regular Expressions in Javascript -


if have string "#review?loanid=12-00034&docid=0" , need select loanid ("12-00034") string, how use single regular expression this?

so far can use /loanid=[\d-]*/ retrieve "loanid=12-00034" how id itself? can nesting regular expression, wondering if possible 1 regex.

this should help

var query = "#review?loanid=12-00034&docid=0"  var matches = /\bloanid=([-\d]*)/.exec(query)  console.log(matches[1]);  // => 12-00034 

this pretty similar other answers, here main difference i'm using \b word boundaries prevent regexp matching incorrect id in whateverloanid=123&loanid=123-456

the second difference capture group ([-d]*). means if string has empty loanid ?loanid=&something=foo, won't typeerror matches[1]


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -