Reputation: 49
Is it possible to match the link which contain specific text using regex? I need to add some text after href value. I tried to match "word" in following link:
<a href="http://word/sth">some link</a>
I tried this, but without success:
(https?:\/\/[^word"]+)
Upvotes: 0
Views: 54
Reputation: 163217
If it is an option you could use the DOM instead of a regex:
var div = document.createElement('div');
div.innerHTML = '<a href="http://word/sth">some link</a>';
if (div.firstChild.innerHTML.indexOf("some") !== -1) {
console.log("contains some!");
div.firstChild.href += " added text";
}
console.log(div.firstChild);
Upvotes: 0