javascript - Whats wrong with this regex logic -


i trying fetch value after equal sign, works getting duplicated values , idea whats wrong here?

 // regex finding word after "=" sign  var myregexpnew = /=(\s*)/g;  // regex finding word before "=" sign  var mytype = /(\s*)=/g;  //setting data grid column  var strnew = "qcbyid=20";  var matchnew = myregexpnew.exec(strnew);  var newtype = mytype.exec(strnew);  alert(matchnew); 

https://jsfiddle.net/6vjjv0hv/

exec returns array, first element global match, following ones submatches, that's why ["=20", "20"] (using console.log here instead of alert make clearer get).

when looking submatches , using exec, you're interested in elements starting @ index 1.

regarding whole parsing, it's obvious there better solution, using 1 regex 2 submatches, depends on real goal.


Comments