If you need to match an http address in python that may or may not have http, here it is (thanks for nothing #python!):
a = re.compile(r"(http://)?(?P[^/]+)(/)?")
Related posts:
If you need to match an http address in python that may or may not have http, here it is (thanks for nothing #python!):
a = re.compile(r"(http://)?(?P[^/]+)(/)?")
Related posts:
This entry was posted on October 10, 2006, 7:16 pm and is filed under General. You can follow any responses to this entry through RSS 2.0. Both comments and pings are currently closed.
Arclite theme by digitalnature | powered by WordPress
#1 by dAniel hAhler on October 10, 2006 - 9:46 pm
a = re.compile(r"(https?://)?(?P[^/]+)(/)?")
would also catch https addresses.
#2 by BlackJack on October 13, 2006 - 12:37 pm
>>> import re
>>> a = re.compile(r”(http://)?(?P[^/]+)(/)?”)
Traceback (most recent call last):
File “”, line 1, in ?
File “/usr/lib/python2.4/sre.py”, line 180, in compile
return _compile(pattern, flags)
File “/usr/lib/python2.4/sre.py”, line 227, in _compile
raise error, v # invalid expression
sre_constants.error: unknown specifier: ?P[
#3 by mindwarp on October 13, 2006 - 9:52 pm
Actually wordpress ate the important part, after P it should say < then base name >