javascript - How to improve this regex -


i have regex find part of <a href=""> within innerhtml of div.

      var b = this.innerhtml.match(/href="([^\'\"]+)/g);       var c = b[0].split('#')[1];       window.location.assign('#'+c); 

and rid of second line, .split function. there way this? ideally, i'd keep hashtag before div, too:

the hrefs allways (only number subject change):

href="#div46"  href="#div47" ... 

you can use:

var b = this.innerhtml.match(/href=(['"])(.+?)\1/); window.location.assign( b[2] ); // #div46 
  • remove g flag matched groups in resulting array.

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -