[Tutor] use of raw strings with regular expression patterns

Manprit Singh manpritsinghece at gmail.com
Fri Nov 6 13:56:51 EST 2020


Dear Sir ,

I have tried to find all matches in a string that starts with a (.), then
the next character  is a lowercase alphabet and then a digit.

s = "a.b.c.d1.1ef.g5"
re.findall('\.[a-z][0-9]', s)

is the way i have used the RE patterns  ok ?

On Fri, Nov 6, 2020 at 11:04 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list