Kir Kir - 1 year ago 80
Python Question

Pyyhon regular expression works on OSx but not on Windows

expression = re.compile(ur'\?(.*)')

The expression is simple and this project was originally built on a mac. It runs fine on the mac, however it doesn't run on windows failing with

File "path/to/scrapy/spiders/", line 42
expression = re.compile(ur'\?(.*)')

Answer Source

It is not about Mac vs Windows, I suspect, it is about the Python version you are using to run this code on.

When I run this code on Python 2.7 - it runs fine, no problems. On Python 3.5 I get a SyntaxError (cause of the u prefix, of course):

  File "/Users/user/SO/", line 3
    expression = re.compile(ur'\?(.*)')
SyntaxError: invalid syntax

Check that you are actually using Python 2 on both machines.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download