I'd recommend using an HTML parser over a regex, but still here's a regex that will create a capturing group over the value of the href
attribute of each links. It will match whether double or single quotes are used.
<as+(?:[^>]*?s+)?href=(["'])(.*?)1
You can view a full explanation of this regex at here.
Snippet playground:
const linkRx = /<as+(?:[^>]*?s+)?href=(["'])(.*?)1/;
const textToMatchInput = document.querySelector('[name=textToMatch]');
document.querySelector('button').addEventListener('click', () => {
console.log(textToMatchInput.value.match(linkRx));
});
<label>
Text to match:
<input type="text" name="textToMatch" value='<a href="google.com"'>
<button>Match</button>
</label>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…