1. *表示匹配任意多个字符 d*表示匹配任意多个数字字符
import re
text = "123h1ello world"
text1 = "123Hello world456"
text2 = "hello world"
res = re.match("d*", text)
res1 = re.match("d*", text1)
res2 = re.match("d*", text2)
print(res.group())
print(res1.group())
print(res2.group())
输出结果为
123
123
Process finished with exit code 0
示例2:*
需求:匹配出,一个字符串第一个字母为大小字符,后面都是小写字母并且这些小写字母可有可无
import re
#注意是前一个字符
ret = re.match("[A-Z][a-z]*","M")
print(ret.group())
ret = re.match("[A-Z][a-z]*","AaBcDE")