天天看點

python——re子產品:方法

findall:找到全部比對

search:查到第一個,找到傳回一個對象,用group()方法顯示

match:同search,不過僅在字元串開始處進行比對

split:分割

sub:替換

subn:(替換, 替換次數)

compile:編譯

>>> com = re.compile("\d+")
>>> com.findall("sfhkhfd321fdshk333fksdjk534")
['321', '333', '534']
           

finditer:疊代器

繼續閱讀