Home > database >  Python Regex - Unknown extension "?>"
Python Regex - Unknown extension "?>"

Time:12-10

I have a simple regex pattern that the python re library claims it's unable to interpret. Specifically the ? some character. This is the regex pattern im trying to compile:

  • (?>\d\d){1,2}

Entire code snippet:

import re
restr = r"\(?>\d\d){1,2}"
string = "12"

regex = re.compile(restr)

regex.search(string)

Error returned:

File "C:\Users\~USER~\AppData\Local\Programs\Python\Python39\lib\sre_parse.py", line 823, in _parse
    raise source.error("unknown extension ?"   char,
re.error: unknown extension ?> at position 1

i've searched high and low an can't seem to find the cause of the issue. All the help is greatly appreciated. I've read about the re flags and different matching methods but it's just the characters that do not work.

CodePudding user response:

Python only supports atomic grouping and possessive quantifiers from version 3.11.

  • Related