英语单词 digit /ˈdɪdʒɪt/ n. 数字; (从 0 到 9 的任何一个)数位;
\d 匹配任意数字,等价于 [0-9]
xxxxxxxxxximport re txt: str = "你好123测试"pattern: str = r"\d\d\d" # 等价于 "[0-9]{3}" 或 "[0-9]+"results: list = re.search(pattern=pattern, string=txt)print(results) #<re.Match object; span=(2, 5), match='123'>
xxxxxxxxxx
import re
txt: str = "你好123测试"
pattern: str = r"\d\d\d" # 等价于 "[0-9]{3}" 或 "[0-9]+"
results: list = re.search(pattern=pattern, string=txt)
print(results) #<re.Match object; span=(2, 5), match='123'>
\D 匹配任意非数字,除了数字其它字符都可能匹配。
re.search(pattern,string)示例
xxxxxxxxxximport re txt: str = "你好123测试"pattern: str = r"\D+"results: list = re.search(pattern=pattern, string=txt)print(results) # <re.Match object; span=(0, 2), match='你好'>
pattern: str = r"\D+"
print(results) # <re.Match object; span=(0, 2), match='你好'>
re.findall(pattern,string)示例
xxxxxxxxxximport re txt: str = "你好123测试"pattern: str = r"\D+"results: list = re.findall(pattern=pattern, string=txt)print(results) # ['你好', '测试']
results: list = re.findall(pattern=pattern, string=txt)
print(results) # ['你好', '测试']
正则表达式付费代写、咨询、答疑解惑,专业、快速、高效帮您解决正则表达式方面的各种问题,可定制各类软件应用程序。
正则学习工作必备在线工具合集
.
^
$
\d
\w
\s
\D
\W
\S
[abc]
[a-z]
[^abc]
aa|bb
?
*
+
{n}
{n,}
{m,n}
(
)
\1
(?:
(?=
(?!
在线客服QQ:543690914,备案号: 苏ICP备15037649号-32。东海县白塔埠镇佳诚电脑经营部版权所有。