0

I have a simple Python function:

return re.search("^([0-9a-zA-Z](?>[-.\\w]*[0-9a-zA-Z])*+@(?>[0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)++[a-zA-Z]{2,9})$", msg)

However, I get the following error message when I go to run my tests:

#13 1.260     itemsappend(_parse(source, state, verbose, nested + 1,
#13 1.260   File "/usr/local/lib/python3.8/sre_parse.py", line 823, in _parse
#13 1.260     raise source.error("unknown extension ?" + char,
#13 1.260 re.error: unknown extension ?> at position 14

Any ideas? I'm unsure why it's happening since the pattern works fine in Java.

  • Why do you assume that Java's regex syntax is equal (or at least subset) of Python's regex syntax? In reality it is not, see https://stackoverflow.com/questions/10492180/differences-in-regex-syntax-between-python-and-java – Daweo Jun 30 '21 at 06:55
  • To prevent backtracking on a pattern, as per: https://stackoverflow.com/questions/15413594/what-does-mean-in-a-pcre-regex – user15882500 Jun 30 '21 at 06:55
  • Python doesn't support atomic grouping, but you can [emulate it.](https://stackoverflow.com/a/13577411/7431860) – Nick Reed Jun 30 '21 at 06:55

0 Answers0