1

I want to remove all occurrences of URL [full path, query string] from the text in Python. Any suggestions on how to do this? I am new to regex!

http://example.com/url/?x=data

This whole URL should be removed! Thanks

Gumbo
  • 643,351
  • 109
  • 780
  • 844
kevin
  • 4,177
  • 10
  • 32
  • 33
  • 2
    What appears outside of the url? Will it always end with double or single quotes, for example? Or a space? – Skilldrick Dec 18 '09 at 18:05

3 Answers3

1

This is definitely a non-trivial task assuming you want to remove any valid URL. I'd take a look at the Regex Lib page on the topic.

theraccoonbear
  • 4,283
  • 3
  • 33
  • 41
1

This previous question will get you off to a good start to match the URL, (ie. RegExLib.com) then its just a matter of the removal

Community
  • 1
  • 1
curtisk
  • 19,950
  • 4
  • 55
  • 71
-1

URL remove Example

<?php
    preg_match_all('/<a.*?href=".*?">(.*?)<[\/]a>/', $content,$arr);

    $new_content = str_replace($arr[0], $arr[1], $content);
    echo $new_content;
?>
J. Chomel
  • 8,193
  • 15
  • 41
  • 69