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