[Tutor] Need help on regular expresions

Manprit Singh manpritsinghece at gmail.com
Sat Nov 6 11:01:17 EDT 2021


Dear sir ,

A little modification in my last mail,

Dear Sir ,
Let's say i have to find if a string in question is of length 10, contains
four digits, one underscore and all other 5 characters must be alphabets
(upper or lowercase)

How would I do it with regular expressions ? Since this problem will be
very ugly with regular string methods,  that's why I would like to try it
with re's.

The below given example only checks if the string x is made up of 10
characters and contains numbers from 0-9 an underscore and alphabets a-z
and A-Z, but no count checks of numbers and alphabets and underscore . How
to do it?

import re
x = "aG4cD1_23fg"
if re.fullmatch(r'\w{10}', x):
    print("Match found")
else:
    print("No match")

Kindly guide

Regards
manprit Sing

On Sat, Nov 6, 2021 at 8:23 PM Manprit Singh <manpritsinghece at gmail.com>
wrote:

> Dear Sir ,
> Let's say i have to find if a string in question is of length 10, contains
> at least four digits, one underscore and all other 5 characters must be
> alphabets (upper or lowercase)
>
> How would I do it with regular expressions ? Since this problem will be
> very ugly with regular string methods,  that's why I would like to try it
> with re's.
>
> The below given example only checks if the string x is made up of 10
> characters and contains numbers from 0-9 an underscore and alphabets a-z
> and A-Z, but no count checks of numbers and alphabets and underscore . How
> to do it?
>
> import re
> x = "aG4cD1_23fg"
> if re.fullmatch(r'\w{10}', x):
>     print("Match found")
> else:
>     print("No match")
>
> Kindly guide
>
> Regards
> manprit Singh
>
>
>


More information about the Tutor mailing list