[英]How do I find the size of a hex string in bytes using Python3 (with regex)
[英]How to find a string from text file by using regex python3?
如何使用正則表達式查找單詞?
file.txt
CLIENT BILL
BILL
FINAL BILL
TOTAL BILL
python代碼
import re
with open('file.txt','r') as f:
input_file = f.readlines()
for i in input_file:
s = re.findall(r'L/sBILL',i)
print(s)
預期產量:
FINAL BILL
TOTAL BILL
為此,請使用re.match
以及另一種模式:
for i in input_file:
if re.match('\w+(s|L) BILL', i.rstrip()):
print(i.rstrip())
輸出:
FINAL BILL
TOTAL BILL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.