Skip to content

Instantly share code, notes, and snippets.

@brendon-codes
Created March 27, 2012 04:14

Revisions

  1. Brendon Crawford revised this gist Jul 1, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions url_matcher.py
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@ def url_matcher():
    See: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
    """
    return re.compile(
    ur"""(?i)\b((?:https?://|www\d{0,3}[\.]|[a-z0-9\.-]+[\.][a-z]{2,4}/)"""
    """(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+"""
    """(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)"""
    """|[^\s`!()\[\]{};:'"\.,<>\u00AB\u00BB\u201C\u201D\u2018\u2019]))"""
    ur"""(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)"""
    ur"""(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+"""
    ur"""(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()"""
    ur"""\[\]{};:'".,<>?\u00AB\u00BB\u201C\u201D\u2018\u2019]))"""
    )
  2. Brendon Crawford revised this gist Mar 27, 2012. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions url_matcher.py
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,12 @@
    #!/usr/bin/env python

    import re

    def url_matcher():
    """
    See: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
    """
    return re.compile(
    ur"""(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)"""
    ur"""(?i)\b((?:https?://|www\d{0,3}[\.]|[a-z0-9\.-]+[\.][a-z]{2,4}/)"""
    """(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+"""
    """(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)"""
    """|[^\s`!()\[\]{};:'".,<>\u00AB\u00BB\u201C\u201D\u2018\u2019]))"""
    """|[^\s`!()\[\]{};:'"\.,<>\u00AB\u00BB\u201C\u201D\u2018\u2019]))"""
    )
  3. Brendon Crawford renamed this gist Mar 27, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.py → url_matcher.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #!/usr/bin/env python

    import re

    def url_matcher():
  4. Brendon Crawford created this gist Mar 27, 2012.
    12 changes: 12 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import re

    def url_matcher():
    """
    See: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
    """
    return re.compile(
    ur"""(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)"""
    """(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+"""
    """(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)"""
    """|[^\s`!()\[\]{};:'".,<>\u00AB\u00BB\u201C\u201D\u2018\u2019]))"""
    )