[Tutor] use of raw strings with regular expression patterns
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Nov 7 04:08:16 EST 2020
On 06/11/2020 18:56, Manprit Singh wrote:
> 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 ?
What does the interpreter say?
>>> s = "a.b.c.d1.1ef.g5"
>>> import re
>>> re.findall('\.[a-z][0-9]', s)
['.d1', '.g5']
>>>
Apparently it is.
Although, from your earlier email, you should probably
use a raw string
>>> re.findall(r'\.[a-z][0-9]', s)
['.d1', '.g5']
However, in this case it makes no difference.
--
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