Answer the question
In order to leave comments, you need to log in
What regular expression (JS) is suitable for removing links?
Hello. Please tell me the code that will remove all href="" from the page.
Thank you.
Answer the question
In order to leave comments, you need to log in
You don't need regular expressions for this.
And in general, regular expressions are not particularly suitable for parsing HTML, since they are sharpened to work with regular grammars , while HTML is context-free and NOT a regular language.
If you are working with a ready DOM tree on the page, it will be much more efficient to process it not as text, but to use the functions built into js.
document.querySelectorAll('a[href=""]') // найти все элементы a с атрибутом href
.forEach(el => el.removeAttribute('href')) // перебрать элементы и удалить этот атрибут
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question