变更
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import re
|
||||
|
||||
match = re.search(r'[1-9]\d{5}', 'bad116105sfa', flags=0)
|
||||
print(match.group(0))
|
||||
|
||||
match1 = re.match(r'[1-9]\d{5}', 'bad116105sfa', flags=0)
|
||||
# print(match1.group()) # 返回类型为空变量,不用if判断会报错
|
||||
if match1:
|
||||
print(match1.group()) # if 判断出match1为空,输出结果为空
|
||||
# 原因为字符串开始为字母,match1匹配不到字符串
|
||||
|
||||
match2 = re.match(r'[1-9]\d{5}', '116105sfa', flags=0)
|
||||
if match2:
|
||||
print(match2.group()) # 去掉头部字母,则可以取出
|
||||
|
||||
ls = re.findall(r'[1-9]\d{5}', '116105sfa116110sadf', flags=0)
|
||||
print(ls) # 输出类型为列表
|
||||
|
||||
ls1 = re.split(r'[1-9]\d{5}', 'sad116105ej116110')
|
||||
print(ls1) # ['sad', 'ej', '']
|
||||
ls2 = re.split(r'[1-9]\d{5}', 'sad116105ej116110', maxsplit=1)
|
||||
print(ls2) # ['sad', 'ej116110'],剩余部分不做匹配
|
||||
|
||||
for m1 in re.finditer(r'[1-9]\d{5}', '116105sfa 116110sadf'):
|
||||
if m1:
|
||||
print(m1.group(0))
|
||||
|
||||
match14 = re.sub(r'[1-9]\d{5}', 'helloworld', '116105sfa 116110sadf', count=1)
|
||||
print(match14)
|
||||
Reference in New Issue
Block a user