0

I want to remove all the domain names from a string excet example.com from a php string. can anyone please write the regular expression in doing it.

preg_replace("/!http://example.com[^>]+\>/i", "", $string); 

but it is not working. can anyone please in this regards.

Regards,

user2674341
  • 277
  • 2
  • 6
  • 15
  • use a negative lookahead. – Barmar Dec 27 '14 at 13:15
  • @Stony How does that answer make an exception for one doain? – Barmar Dec 27 '14 at 13:16
  • @Barmar its an Regex to remove the domain name so whats the problem? ;) "I wan't to remove ALLLLL domain names from a string" so here are on Stackoverflow are enough answers to solve that problem. – René Höhle Dec 27 '14 at 13:19
  • @Stony **except example.com** – Barmar Dec 27 '14 at 13:22
  • The OP should combine the regexp in the second question with the exception handler in the first question. – Barmar Dec 27 '14 at 13:24
  • @Bamar: I haven't said that its the complete correct answer. When you try to programming something you should think about the problem and try to find a solution with a hint to learn something or what do you think? You are right the solution is to combine the First Answer and exclude the domain you need. But its much easier to filter the string with strpos first and check if your domain you want to keep is in your string and otherwise use the regex. When your regex is to complicated its a problem to change them after a few weeks. – René Höhle Dec 27 '14 at 13:27
  • Can anyone please write the sample code , as i am new to regular expression. actually i am gathering the html source and saving it into a string. i want to remove all the urls except my url that contains my domain name. – user2674341 Dec 27 '14 at 13:41

0 Answers0