2017-06-08 21 views
0

我目前使用python來分析巨大日誌文件中的日誌行,並使用正則表達式來查找這些感興趣的行。找到不匹配的正則表達式的位置

但是,我怎麼能告訴某個不適合正則表達式的位置呢?我無法手動執行此操作,因爲這太痛苦了。

以下面的兩個日誌行爲例,我不明白爲什麼logline不符合給定的標準,而logline2。任何想法如何我可以找出?

>>> reg_mld_str='.*Contract=(?P<feedcode>\S+).*LastPrice=(?P<lastprice>\S+) MatchTotQty=(?P<turnover_vol>\d+) Turnover=(?P<turnover_val>\d+) RiseLimit=(?P<riselimit>\S+) FallLimit=(?P<falllimit>\S+).* BuyPriceOne=(?P<lv1_price_bid>\S+) BuyQtyOne=(?P<lv1_vol_bid>\d+) BuyImplyQtyOne=(?P<lv1_imply_bid>\d+) BuyPriceTwo=(?P<lv2_price_bid>\S+) BuyQtyTwo=(?P<lv2_vol_bid>\d+) BuyImplyQtyTwo=(?P<lv2_imply_bid>\d+) BuyPriceThree=(?P<lv3_price_bid>\S+) BuyQtyThree=(?P<lv3_vol_bid>\d+) BuyImplyQtyThree=(?P<lv3_imply_bid>\d+) BuyPriceFour=(?P<lv4_price_bid>\S+) BuyQtyFour=(?P<lv4_vol_bid>\d+) BuyImplyQtyFour=(?P<lv4_imply_bid>\d+) BuyPriceFive=(?P<lv5_price_bid>\S+) BuyQtyFive=(?P<lv5_vol_bid>\d+) BuyImplyQtyFive=(?P<lv5_imply_bid>\d+) SellPriceOne=(?P<lv1_price_ask>\S+) SellQtyOne=(?P<lv1_vol_ask>\d+) SellImplyQtyOne=(?P<lv1_imply_ask>\d+) SellPriceTwo=(?P<lv2_price_ask>\S+) SellQtyTwo=(?P<lv2_vol_ask>\d+) SellImplyQtyTwo=(?P<lv2_imply_ask>\d+) SellPriceThree=(?P<lv3_price_ask>\S+) SellQtyThree=(?P<lv3_vol_ask>\d+) SellImplyQtyThree=(?P<lv3_imply_ask>\d+) SellPriceFour=(?P<lv4_price_ask>\S+) SellQtyFour=(?P<lv4_vol_ask>\d+) SellImplyQtyFour=(?P<lv4_imply_ask>\d+) SellPriceFive=(?P<lv5_price_ask>\S+) SellQtyFive=(?P<lv5_vol_ask>\d+) SellImplyQtyFive=(?P<lv5_imply_ask>\d+).*GenTime=(?P<ts>\S+) LastMatchQty' 
>>> reg_mld=re.compile(reg_mld_str) 
>>> logline2= '15:19:25.413628808 [Debug ] [LEVEL2_SESSION] [anonymous] [OnBestAndDeep] Info="Level2 PriceDepth." BestAndDeep={Type=1 Length=488 Version=0 Time=0 Exchange= Contract=m1712-P-2550 SuspensionSign=0 LastClearPrice=70.5 ClearPrice=70.5 AvgPrice=0.5 LastClose=70.5 Close=0.5 OpenPrice=0.5 LastOpenInterest=172 OpenInterest=172 LastPrice=0.5 MatchTotQty=2 Turnover=10 RiseLimit=212.5 FallLimit=0.5 HighPrice=0.5 LowPrice=0.5 PreDelta=0 CurrDelta=0 BuyPriceOne=0 BuyQtyOne=0 BuyImplyQtyOne=0 BuyPriceTwo=0 BuyQtyTwo=0 BuyImplyQtyTwo=0 BuyPriceThree=0 BuyQtyThree=0 BuyImplyQtyThree=0 BuyPriceFour=0 BuyQtyFour=0 BuyImplyQtyFour=0 BuyPriceFive=0 BuyQtyFive=0 BuyImplyQtyFive=0 SellPriceOne=0 SellQtyOne=0 SellImplyQtyOne=0 SellPriceTwo=0 SellQtyTwo=0 SellImplyQtyTwo=0 SellPriceThree=0 SellQtyThree=0 SellImplyQtyThree=0 SellPriceFour=0 SellQtyFour=0 SellImplyQtyFour=0 SellPriceFive=0 SellQtyFive=0 SellImplyQtyFive=0 GenTime=15:19:09.609 LastMatchQty=2 InterestChg=0 LifeLow=0.5 LifeHigh=284 Delta=-0.2256374694 Gamma=0.0006061540941 Rho=-0.3017551265 Theta=-0.3659621086 Vega=6.354866111 TradeDate=20170420 LocalDate=}' 
>>> reg_mld.match(logline2) 
<_sre.SRE_Match object at 0x0000000002322BC0> 
>>> logline = '09:26:00.632018658 [Debug ] [LEVEL2_SESSION] [anonymous] [OnBestAndDeep] Info="Level2 PriceDepth." BestAndDeep={Type=1 Length=388 Version=0 Time=30813619 Exchange= Contract=i1709 SuspensionSign=0 LastClearPrice=426.5 ClearPrice=inf AvgPrice=436 LastClose=429.5 Close=inf OpenPrice=427 LastOpenInterest=2088194 OpenInterest=1915258 LastPrice=437.5 MatchTotQty=1935046 Turnover=8.44126785e+10 RiseLimit=460.5 FallLimit=392.5 HighPrice=443 LowPrice=422.5 PreDelta=0 CurrDelta=0 BuyPriceOne=437.5 BuyQtyOne=1122 BuyImplyQtyOne=12 BuyPriceTwo=437 BuyQtyTwo=1683 BuyImplyQtyTwo=175 BuyPriceThree=436.5 BuyQtyThree=1647 BuyImplyQtyThree=0 BuyPriceFour=436 BuyQtyFour=1388 BuyImplyQtyFour=0 BuyPriceFive=435.5 BuyQtyFive=1499 BuyImplyQtyFive=0 SellPriceOne=438 SellQtyOne=1119 SellImplyQtyOne=4 SellPriceTwo=438.5 SellQtyTwo=3414 SellImplyQtyTwo=0 SellPriceThree=439 SellQtyThree=2773 SellImplyQtyThree=1 SellPriceFour=439.5 SellQtyFour=2338 SellImplyQtyFour=0 SellPriceFive=440 SellQtyFive=3440 SellImplyQtyFive=0 GenTime=09:26:01.012 LastMatchQty=4 InterestChg=-172936 LifeLow=343.5 LifeHigh=685 Delta=0 Gamma=0 Rho=0 Theta=0 Vega=0 TradeDate=20170605 LocalDate=}' 
>>> reg_mld.match(logline) 
+0

也許嘗試在https://regex101.com/ –

+0

輸入您的示例數據到工具讓我們更容易,艾瑪。我已將您的代碼放在regex101上:https://regex101.com/r/vH6l5M/1。你可以測試它。 –

+0

你也可以做一個「在線文本差異」來找到更快的問題。 –

回答