原文:Python用re正則化模塊在字符串查找特定字符串

實驗需要,在一個含有幾億個字符的txt文件中查找特定的字符串,首先用re模塊進行查找 re.finditer filename, label str 可以在label str中查找filename的位置,s match.start 返回字符串開始的索引,e match.end ,返回字符串結束的索引。程序運行的結果是 . 耗時 s左右 同樣的,由於txt文件中為一行一行的數據,可以用readlin ...

2017-09-12 12:33 0 8875 推薦指數:

查看詳情

python 字符串查找

python 字符串查找有4個方法,1 find,2 index方法,3 rfind方法,4 rindex方法。 1 find()方法: info = 'abca' print info . find( 'a') ##從下標0開始,查找字符串里第一個出現的子串 ...

Sun Aug 11 04:09:00 CST 2013 0 60561
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM