It is necessary to remove all links where there are Latin letters between the a tags.
I tried to do this:
preg_replace('#<a[^>]*>.*?</a>#is', '', $text); Such an expression removes all links in general.
It is necessary to remove all links where there are Latin letters between the a tags.
I tried to do this:
preg_replace('#<a[^>]*>.*?</a>#is', '', $text); Such an expression removes all links in general.
The correct regular expression looks like this:
preg_replace('#<a[^>]*>.*?[az].*?</a>#is', '', $text); Why do you have a mistake:
In your case,. .*? captures the shortest sequence of any characters before the closing tag </a> .
You need to select only those links in which there are Latin letters.
Need to replace the expression .*? on .*?[az].*? , which means literally the following: to find the shortest possible sequence of any characters among which at least one Latin letter will occur.
You can check the work on the service regex101 .
After the @Visman remark @Visman regular expression was:
preg_replace('#<a[^>]*>[^<]*?[az][^<]*?</a>#is', '', $text); Difference from the previous version: we are looking for the shortest possible sequence of any characters except < , among which there will be at least one Latin letter .
Restrictions
A regular expression will not capture a link with this text: <a href="link"><latin></a> , because the < link is found in the link text.
You can check the work on the service regex101 .
Source: https://ru.stackoverflow.com/questions/536009/
All Articles