First of all, this is not a dupe of this question.
In Javascript this expression seems to be evaluated correctly:
\\/(omniture|mbox|hbx|omniunih)(.*)?
If I pass it to Python re
module, bad things happen. In fact, the following returns an error:
import re
re.compile (u'\\/(omniture|mbox|hbx|omniunih)(.*)?')
In [101]: re.compile (u'\\/(omniture|mbox|hbx|omniunih)(.*)?')
---------------------------------------------------------------------------
error Traceback (most recent call last)
/home/fakk/spider.io/1/<ipython-input-101-b5b19eb3b66e> in <module>()
----> 1 re.compile (u'\\/(omniture|mbox|hbx|omniunih)(.*)?')
/usr/lib/python2.7/re.pyc in compile(pattern, flags)
188 def compile(pattern, flags=0):
189 "Compile a regular expression pattern, returning a pattern object."
--> 190 return _compile(pattern, flags)
191
192 def purge():
/usr/lib/python2.7/re.pyc in _compile(*key)
242 p = sre_compile.compile(pattern, flags)
243 except error, v:
--> 244 raise error, v # invalid expression
245 if len(_cache) >= _MAXCACHE:
246 _cache.clear()
error: nothing to repeat
Python complains about the (.*)?
part, which me myself am not able to understand.
My questions are:
- What does
(.*)?
do in JS? Match zero or one (?
) of zero or more (*
) chars (.
)? What's the point? - How can I translate it in Python?