'()\*\...">

Regex links without tag

(http([s]?):\/\/?)(([a-zA-Z0-9]+(\.?))+)([a-zA-Z0-9]+((\.[a-zA-Z]{2,5}){1,2})((\/[a-zA-Z0-9\?&=_\-\~:/?#[\]@!\$&'()\*\+,;]*)*)((\.[a-zA-Z]{2,5}){0,2}))

This is my regex that works well for matching links in a string. But I do not want him to select every link. If the link is ">before or </a>after it, this link should not be calculated. How can I do that?

They must be matched:

adasdas http://www.stackoverflow.com asdasas
adasdasahttp://www.stackoverflow.com/something asdas

They should NOT be matched:

adasdas<a href="somelink">           http://www.stackoverflow.com     </a>asdasas
adasdasa<a href="somelink">http://www.stackoverflow.com/something</a> asdas

Why do I need it? I want each link to be interactive, even if it is not between anchor tags.

+4
source share
2 answers

regex html, , :

$regex="~<a.*?</a>(*SKIP)(*F)|http://\S+~";

.

"regex-match pattern, ..."

| <a ...tags </a>, , . URL-, , , .

url, , , , .

+9

lookaround c.f.:

0

Source: https://habr.com/ru/post/1547718/


All Articles