I need a regex to find the contents of the hrefs from these a tags :
<p class="bc_shirt_delete">
<a href="/CustomContentProcess.aspx?CCID=13524&OID=3936923&A=Delete" onclick="javascript:return confirm('Are You sure you want to delete this item?')">delete</a>
</p>
Just the urls, not the href/ tags.
I'm parsing a plain text ajax request here, so I need a regex.
You can try this regex:
/href="([^\'\"]+)/g
Example at: http://regexr.com?333d1
Update: or easier via non greedy method:
/href="(.*?)"/g
This will do it nicely. http://jsfiddle.net/grantk/cvBae/216/
Regex example: https://regex101.com/r/nLXheV/1
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]);
}
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 caseIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With