Wrote this regular season:

/<a(.*)href=\"http:\/\/url1(.*)\">(.*)<\/a>/s 

Everything is good, but if there is a link in the text before url1, then obviously both links will be eaten. For example:

 <a href="http://url0">url0</a> text <a href="http://url1">url1</a> 
  • 3
    Use minimal quantification, replace. * With all. *? - ReinRaus
  • To replace the link with url1 - Ivo
  • one
    I recommend here [this] [1]. Excellent help in drafting regulars [1]: gskinner.com/RegExr - Sugar Sugar
  • @ Sugar, the links in the comments work a little differently: [ссылка](http://example.com) - MichaelPak

1 answer 1

You can do the following:

 /<a[^>]+href=\"http:\/\/url1(.*?)\">(.*?)<\/a>/s 
  • I apologize, but in the question, is it indicated that PHP is used? - Sasha Chernykh
  • one
    @ SashaBlack, yes, you are right, removed the "PHP wrapper". - cheops