
September 14th, 2012, 10:20 PM
|
 |
Contributing User
|
|
|
|
hmm, well first I started to figure out the string:
(?i) means ignore case,
then I got the bright idea---try it as a raw string! Notice I inserted an "r" before the '"'. Python has a bunch of ways to express string literals.
Code:
import re
string = "http://www.google.com"
regex = re.compile(r"(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))")
r = regex.search(string)
print(r)
__________________
[code] Code tags[/code] are essential for python code!
|