2017-06-08 3 views
0

Ich verwende derzeit Python, um die Protokollzeilen aus einer umfangreichen Protokolldatei zu analysieren, und ich verwende den regulären Ausdruck, um diese interessanten Zeilen herauszufinden.Position der nicht übereinstimmenden Position des regulären Ausdrucks suchen

Wie könnte ich jedoch eine bestimmte Position angeben, die nicht in die Regex passt? Ich kann das nicht manuell machen, weil es zu schmerzhaft ist.

Nehmen Sie die folgenden zwei Protokollzeilen als Beispiel, ich verstehe nicht, warum logline stimmt nicht mit dem angegebenen Standard, während logline2 tut. Irgendeine Idee, wie ich herausfinden kann?

>>> 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

Vielleicht versuchen Sie Ihre Beispieldaten in das Werkzeug bei https://regex101.com/ Eingabe –

+0

Lassen Sie uns es einfacher machen, Emma. Ich habe Ihren Code auf regex101 gesetzt: https://regex101.com/r/vH6l5M/1. Sie können es ausprobieren. –

+0

Sie können auch ein "Online-Text-Diff" durchführen, um das Problem schneller zu finden. –

Antwort

0

Das Problem ist auf

Umsatz = 8.44126785e + 10

wenn ich ersetzen, dass für so etwas wie:

Umsatz = 84412678510

Ihre Regex entsprechen: https://regex101.com/r/vH6l5M/2