Here is a robust solution:
let href_regex = /<a([^>]*?)href\s*=\s*(['"])([^\2]*?)\2\1*>/i,
link_text = '<a href="/another-article/">another article link</a>',
href = link_text.replace ( href_regex , '$3' );
href
attribute=
'
and "
so you DRY'
and "
i
ignore caseThis will do it nicely. http://jsfiddle.net/grantk/cvBae/3/
var str = '<p href="missme" class="test"><a href="/CustomContentProcess.aspx?CCID=13524&OID=3936923&A=Delete" onclick="">delete</a></p>'
var patt = /<a href="(.*?)"/g;
while(match=patt.exec(str)){
alert(match[1]);
}
how about spaces around = ? this code will fix it:
var matches = str.match(/href( *)=( *)("|'*)(.*?)("|'*)( |>)/);
console.log(matches);