Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a `SyntaxWarning: invalid escape sequence \s` warning?

Tags:

python-3.x

re.compile('\s+', flags = re.UNICODE)

The above code gives the following warning in python3.

SyntaxWarning: invalid escape sequence \s

I fix it by using r'\s+'. Is it a correct way to fix the problem?

like image 361
user1424739 Avatar asked Dec 31 '25 13:12

user1424739


1 Answers

Yes, that is. You can either use a raw string r'\s+' or alternatively escape the backslash with '\\s+'.

like image 118
ruohola Avatar answered Jan 03 '26 06:01

ruohola



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!