gpt4 book ai didi

python - [\w\d] 中的\d 不是多余的吗?

转载 作者:行者123 更新时间:2023-12-04 19:02:48 24 4
gpt4 key购买 nike

我正在读一本书,看到很多这样的例子:

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

\w意味着 [a-zA-Z0-9_] , \d意味着 [0-9] , \d\w 的子集.
那么,那些 "\d"不是多余的吗?请有人确认我的理解是正确的,因为这让我发疯。

最佳答案

是的,这是多余的,而且很简单 \w也能正常工作。见 https://docs.python.org/2/library/re.html

\d

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

\w

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

关于python - [\w\d] 中的\d 不是多余的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33485717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com