小弟刚学python,想用正则表达式提取一些信息,但是不知道为什么都没用,求大神指教。
Code:
import sys
import re
filePath = "E:/PythonProject/Reg/test.txt"
file = open(filePath,"r")
pattern = re.compile("<[\w\W]*>")
#pattern = re.compile("\d{2}:\d{2}:\d{2}:\d{3}")
#注释的这条能够正确执行
info = ""
for line in file:
info = info + line
print("info is:%s"%(info))
match = pattern.match(info)
if match:
print("!!!match!!!")
print(match.group())
txt:
19:00:04:735 OnRecvData:
收到客户端:172.16.166.15 的信息
<?xml version="1.0" encoding='gb2312'?>
<Headbeat_Req>
<Cookie>1832</Cookie>
<SytemTime>2013-05-15 18:58:57</SytemTime>
</Headbeat_Req>
Code:
import sys
import re
filePath = "E:/PythonProject/Reg/test.txt"
file = open(filePath,"r")
pattern = re.compile("<[\w\W]*>")
#pattern = re.compile("\d{2}:\d{2}:\d{2}:\d{3}")
#注释的这条能够正确执行
info = ""
for line in file:
info = info + line
print("info is:%s"%(info))
match = pattern.match(info)
if match:
print("!!!match!!!")
print(match.group())
txt:
19:00:04:735 OnRecvData:
收到客户端:172.16.166.15 的信息
<?xml version="1.0" encoding='gb2312'?>
<Headbeat_Req>
<Cookie>1832</Cookie>
<SytemTime>2013-05-15 18:58:57</SytemTime>
</Headbeat_Req>