我正在处理日志文件过滤器。我想检查日志文件中是否存在多个输入文本行。以下是我的一些文本行。
Instrument ID = 121212121
Book Definition ID = NORMAL
Trader ID = TRQ01
Order Type = 2
Source ID = <Unset>
Instrument Index = <Unset>
Value = <Unset>
Side = 2
Qualifier = <Unset>
Order Qty = <Unset>
Visible Size = <Unset>
TIF = 0
以下是我日志文件的一部分。
~|A|SMsg:Sequenced Message{
~|A|{
~|A| Routing Seq = 28545
~|A| Origin = 1
~|A| Transaction ID = 28483
~|A| Sequenced Message = ~|A| SMsgLite:NEW NEW ORDER
~|A| {
~|A| Instrument ID = 121212121
~|A| Book Definition ID = NORMAL
~|A| Trader ID = TRQ01
~|A| Order Type = 2
~|A| Source ID = <Unset>
~|A| Instrument Index = <Unset>
~|A| Value = <Unset>
~|A| Side = 2
~|A| Qualifier = <Unset>
~|A| Order Qty = <Unset>
~|A| Visible Size = <Unset>
~|A| TIF = 0
~|A| Order Sub Type = 3
~|A| Inactive Time = <Unset>
~|A| Expiration Date = <Unset>
~|A| Contingent Value = <Unset>
~|A| Owner ID = TRQ01
~|A| Client Order ID = 380-6XAC3Vw6W
~|A| Transact Time = <Unset>
~|A| Symbol = <Unset>
~|A| IsSurveillance = 1
~|A| Reason = sd
~|A| Gateway Rejection = <Unset>
~|A| Order Reject Code = <Unset>
我有两个主要问题
我想在匹配时忽略"~|A| "
字符集。这意味着我想在该行的第5个字符位置开始匹配。
我想找到上面文字行的完整匹配。 这是我的查找功能
def BooleanLookup(self,infile,regex,start,end):
self.infile = infile
self.regex = regex
self.start = start
self.end = end
for line in itertools.islice(infile,start,end):
line = line.rstrip()
if re.match(regex, line):
return True
break
else:
return False
但即使字符串的一部分匹配,它也会返回true。如何实现一种完全匹配的方法。
答案 0 :(得分:0)
re.match(regex,line)将返回一个对象。如果您想使用您的代码,请更改
if re.match(regex, line):
到
if re.match(regex, line) and re.match(regex,line).span()[1] = len(line):