Regular expression for href and www/https/http links

Asked

Viewed 1,229 times

2

Good morning, I have 2 regular expressions, where one serves to get the URL of any href, and another that I need to arrange that would just be to get the URL’s that are not inside a href, ie, only the URL’s typed with start www, https:// and http://. With the second expression I can’t get the urls inside the href.

1°Expression to catch the href

preg_replace('/href="(?!http:\/\/)([^"]+)"/e', '$this->href("$1", "$id", "$posi_email")', $texto);

2°Expression that should not pick up the urls inside a href.

preg_replace('/(www.|http:\/\/|https:\/\/)[^ ]+?([^,])+)/e', '$this->url("$1", "$id", "$posi_email")', $texto);
  • I was in doubt in your second expression with what you need to match the text. It would be any page link?

  • Be very careful with that preg_replace modifier e. Has already been depreciated!

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.