kevin
kevin

Reputation: 4357

regex to remove URL from text

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

Upvotes: 1

Views: 4572

Answers (3)

Shelly Chen
Shelly Chen

Reputation: 15

URL remove Example

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

    $new_content = str_replace($arr[0], $arr[1], $content);
    echo $new_content;
?>

Upvotes: -1

curtisk
curtisk

Reputation: 20175

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

Upvotes: 1

theraccoonbear
theraccoonbear

Reputation: 4337

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.

Upvotes: 1

Related Questions