0

I have a regex expression which gets validated in python 2.7 but shows as invalid syntax in python 3.5

$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re 
>>> a = re.compile(ur"^([^[?]+)(\[\])?(\?)?$")
>>>

$ python3.5                                                        
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re 
>>> a = re.compile(ur"^([^[?]+)(\[\])?(\?)?$")
  File "<stdin>", line 1
    a = re.compile(ur"^([^[?]+)(\[\])?(\?)?$")
killerx
  • 45
  • 8
  • 1
    `'ur'` syntax isn't supported in Py3, see https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals – Dimitris Fasarakis Hilliard May 18 '17 at 09:35
  • @vaultah that duplicate is pretty misleading. Although the `u` prefix was initially invalid in Python3, it has been restored since 3.3; it's just `ur` that is no longer valid. – Daniel Roseman May 18 '17 at 09:37
  • @DanielRoseman feel free to reopen this question. I'll try to find a better dupe target. – vaultah May 18 '17 at 09:37
  • vaultah, DanielRoseman, JimFasarakisHilliard: Your comments seem to resolve my query well. Thanks for your help! :) – killerx May 18 '17 at 09:42

0 Answers0