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
Post a Comment