[Tutor] use of raw strings with regular expression patterns

Mats Wichmann mats at wichmann.us
Fri Nov 6 12:06:36 EST 2020


On 11/6/20 10:03 AM, Manprit Singh wrote:
> Dear sir ,
> 
> As you know there are some special characters in regular expressions , like
> :
> \A, \B, \b, \d, \D, \s, \S, \w, \W, \Z
> 
> is it necessary to use raw string notation like r'\A' while using  re
> patterns made up of these characters ?

it's recommended, yes.  Otherwise you have a conflict on who processes 
the escapes, entering as a raw string tells Python to keep its hands off.

checkers will give you warnings if you use escapes that don't look like 
Python's own escapes, and you didn't enter as a raw string.




More information about the Tutor mailing list