1. 程式人生 > >python正則表達式

python正則表達式

表達式 {} spa 執行 color dal 表達 pri 則表達式

元字符 . ^ $ * + ? {} [] | () \

. 匹配除換號符以為的任意一個符號

ret=re.findall(李.,李傑,李剛,王超,占山,李蓮英)
print(ret)
執行結果
[李傑, 李剛, 李蓮]
ret2=re.findall(李..,李傑,李剛,王超,占山,李蓮英)
print(ret2)
執行結果
[李傑,, 李剛,, 李蓮英]

^ 以指定字符開頭

ret3=re.findall(^李.,yuan李傑,李剛,王超,占山,李蓮英)
print(ret3)
執行結果
[]

$ 以指定字符結尾

ret=re.findall(
英$,yuan李傑,李剛,王超,占山,李蓮英) print(ret) 執行結果 []

python正則表達式