[Tutor] Need help on regular expresions
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Nov 6 21:08:48 EDT 2021
On 06/11/2021 16:11, Manprit Singh wrote:
> Dear Richard,
>
> I know this can be done with string methods, I was just willing to know if
> this can be done using re in an easy way or not .
For some definition of easy...
if ((len(s) == 10) and
(len(re.findall(r'\d',s)) == 4) and
(len(re.findall(r'[a-zA-Z]',s)) == 5) and
'_' in s):
print("Success")
else: print("Fail!")
But I'm not sure that's any easier than using the plain string methods.
--
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