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.

    1 answer 1

    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 .


    Update

    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 .

    • In order not to tule near each symbol * question mark, sufficiently indicate the modifier: "U - inverts greed." It will remove thereby gluttony. - Vlad Vlad
    • @VladVlad, I agree, but note that in this regular season the first asterisk has no question mark. - VenZell
    • Thank you all for the help! - Sharp - eyed
    • one
      @VenZell, the joke of your regular season is that it captures something completely different from what the questioner was expecting. Regex101.com/r/qS8bY7/1 - Visman
    • @Visman, I added the answer. Thanks for watching! - VenZell