python – Regex does or does not give an error depending on which REPL is used

Consider the following Python code using the regex library re

import re
re.compile(rf"{''.join(['{c}\\s*' for c in 'qqqq'])}")

I have run it in two different REPLs:

www.pythonmorsels.com/repl/
www.online-python.com/#google_vignette

The first of which gives no error, and the second give the following error:

File "main.py", line 2
    re.compile(rf"{''.join(['{c}\\s*' for c in 'qqqq'])}")
               ^
SyntaxError: f-string expression part cannot include a backslash

I’d like to understand why I get an error sometimes and not others. How can I proceed to narrow down exactly where the difference is?

Read more here: Source link