[Tutor] use of raw strings with regular expression patterns

Alan Gauld alan.gauld at yahoo.co.uk
Fri Nov 6 12:33:39 EST 2020


On 06/11/2020 17:03, 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 not necessary in the sense that Python will allow you
not to. But it is *very strongly recommended*, otherwise some
unexpected results are likely.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list