Regex for URL extracting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johny

    #1

    Regex for URL extracting

    Does anyone know about a good regular expression for URL extracting?

    J.

  • Nikita the Spider

    #2
    Re: Regex for URL extracting

    In article <1169655624.981 833.29730@j27g2 000cwj.googlegr oups.com>,
    "Johny" <python@hope.cz wrote:
    Does anyone know about a good regular expression for URL extracting?
    Extracting URLs from what?

    If it is HTML, then I'd look at some existing HTML parsing modules like
    Beautiful Soup and Barnes' HTMLData.

    --
    Philip

    Whole-site HTML validation, link checking and more

    Comment

    • Paul McGuire

      #3
      Re: Regex for URL extracting

      On Jan 24, 10:20 am, "Johny" <pyt...@hope.cz wrote:
      Does anyone know about a good regular expression for URL extracting?
      >
      J.
      Google turns this up:

      Update 8/11/2009: This post has moved and a new better version of the regex is there: http://flanders.co.nz/2009/11/08/a-good-url-regular-expression-repost…


      But I've seen other re's for this problem that are hundreds of
      characters long.

      -- Paul

      Comment

      • Chris Mellon

        #4
        Re: Regex for URL extracting

        On 24 Jan 2007 11:07:49 -0800, Paul McGuire <ptmcg@austin.r r.comwrote:
        On Jan 24, 10:20 am, "Johny" <pyt...@hope.cz wrote:
        Does anyone know about a good regular expression for URL extracting?

        J.
        Google turns this up:
        >
        Update 8/11/2009: This post has moved and a new better version of the regex is there: http://flanders.co.nz/2009/11/08/a-good-url-regular-expression-repost…

        >
        But I've seen other re's for this problem that are hundreds of
        characters long.
        >
        -- Paul
        >
        --

        >
        These are the regexps that gnome-terminal uses for it's URL
        auto-recognition, and I have shamelessly stolen them for use in one of
        my own apps:

        urlfinders = [
        re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|t elnet|nttp|file |http|ftp|https )://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\ \*\\(\\),;:@&=\ \?/~\\#\\%]*[^]'\\.}>\\),\\\"]"),
        re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|t elnet|nttp|file |http|ftp|https )://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?"),
        re.compile("(~/|/|\\./)([-A-Za-z0-9_\\$\\.\\+\\!\ \*\\(\\),;:@&=\ \?/~\\#\\%]|\\\\
        )+"),
        re.compile("'\\ <((mailto:)|)[-A-Za-z0-9\\.]+@[-A-Za-z0-9\\.]+"),
        ]

        Comment

        Working...