S
S
sputnickk2021-10-20 10:03:56
HTML
sputnickk, 2021-10-20 10:03:56

How to remove a link with an exception?

Hello. Guys tell me how to add an exception to the regular expression.

I need to remove links, but leave the anchor, for example:

1) <a href="https://qna.habr.com/">Некая ссылка 1</a>
2) <strong><a href="#">Некая ссылка 2</a></strong>
3) <strong><a class="_5ayv _qdx" href="/hashtag/творческие"><span class="_5aw4 _qdz">#</span><span class="_5ayu">творческие</span></a>

Должно в исходнике получиться так:

1) Некая ссылка 1
2) Некая ссылка 2
3) творческие
---
т е ссылки вырезали, остались только анкоры...


but to exclude links with class "mylinks"

to link:
<a class="mylinks"  href="https://qna.habr.com/">моя ссылка 1</a>

не трогало совсем


Theoretically, it seems like this:
<a (?!mylinks) href="(.*?)">.*?</a>

but something does not work out at all

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Abramov, 2021-10-20
@Gvoz1

If in an element with a strict order (the class comes first), You can do thisclass="mylinks"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question