Is \ d redundant in [\ w \ d]?

I read a book and see a ton of examples like this:

(?P<email> [\w\d.+-]+ # username @ ([\w\d.]+\.)+ # domain name prefix (com|org|edu) # limit the allowed top-level domains ) 

Since \w means [a-zA-Z0-9_] , \d means [0-9] , \d is a subset of \w .
So, aren't these "\ d" redundant? Please, someone will confirm that my understanding is correct, because it makes me gat.

+5
source share
1 answer

Yes, this is redundant, and simple \w will work just as well. See https://docs.python.org/2/library/re.html

\d

If the UNICODE flag is not specified, it matches any decimal digit; this is equivalent to the set [0-9] . With UNICODE it will correspond to what is classified as a decimal digit in the Unicode character property database.

\w

If the LOCALE and UNICODE flags are not specified, they match any alphanumeric character and underscore; this is equivalent to the set [a-zA-Z0-9_] . With LOCALE it will match the set [0-9_] plus any characters defined as alphanumeric for the current locale. If UNICODE set, it will match the characters [0-9_] plus everything that is classified as alphanumeric in the Unicode character property database.

+5
source

Source: https://habr.com/ru/post/1235050/


All Articles