2016-02-29 43 views
1

我收到了一個消息,其結構如下,消息從標記20開始,結束於86 :.我想編寫一個正則表達式來提取所有消息。 我會寫一個C#實用程序來提取每條消息並將其放入ArrayList中。正則表達式去糾正MT940消息

:20:160212-2359 
:21:600******444 
:28C:00001/00001 
. 
. 
. 
:86:DAILY SETTLEMENT /ENTRY-13 MAR 
:62F:D160212GBP1229387,45 
:64:D160212GBP1229387,45 
:65:D120314GBP1229387,45 
:65:D120315GBP1229387,45 
:65:D120316GBP1229387,45 
:65:D120317GBP1229387,45 
:65:D120318GBP1229387,45 
:86:FORWARD AVAILABLE FUNDS SHOW ITEMS KNOWN BUT NOT YET POSTED 
some more comments in 86_2 segment 
this is line2 
:20:160212-2359 
:21:B***22 
:25:60*****88 
. 
. 
. 
:86:/ENTRY-13 MAR TRF/REF 6*******64 /ORD/ some line here 
*********************** /BNF/ JO 88 
:62F:C160212EUR13868931,00 
:64:C160212EUR13868931,00 
:65:C120314EUR13868931,00 
:65:C120315EUR13791849,00 
:65:C120316EUR13791849,00 
:65:C120317EUR13791849,00 
:65:C120318EUR13791849,00 
:86:FORWARD AVAILABLE FUNDS SHOW ITEMS KNOWN BUT NOT YET POSTED 
some more comments in 86_2 segment. 
:20:160212-2359 
:21:B****X 
:25:6*************1 
:28C:00001/00001 
:86:STORE1 EUROPE B.V. /ENTRY-15 MAR RTS/REF 6*****6 RTS 
SWEPT FROM 9999 1**** XX***********BILLING CHARGES - 
28FEB12 TRF/REF 6641XXX43799053 /ITEMCNT/004 /BNF/ /ITEMCNT/004 
BILLING CHARGES 
:61:1203130313DR10000000,00****288//6*****6 
:86:STORE1 CNRTY SRL /ENTRY-13 MAR CLG/REF 66**********6 
:61:1*****000,00NT*****9846//6******74 
:86:NAME /ENTRY-13 MAR CLG/REF 6******4 LA C****R 
**** CASH DEPOSIT STORE1 
:61:1203150315DR48531,00NCHGBILLING CHARGES//6641XXX43799053 
:86:BILLING CHARGES - 28FEB12 /ENTRY-15 MAR TRF/REF 
66******53 /ITEMCNT/004 
:62F:C160212EUR0,00 
:64:C160212EUR0,00 
:65:C120314EUR0,00 
:65:C120315EUR0,00 
:65:C120316EUR0,00 
:65:C120317EUR0,00 
:65:C120318EUR0,00 
:86:FORWARD AVAILABLE FUNDS SHOW ITEMS KNOWN BUT NOT YET POSTED 
{newline} 

將實際值替換爲'*'字符。

感謝 DHIRAJ Bhavsar

+0

@ Trim007:我的歉意,早些時候我忘了提及:86:在消息中重複。 –

回答

0

試試這個

​​

代碼

/:20:(.*?):86:/gs 

https://regex101.com/r/dW4zS3/1

.*?匹配任意字符零和無限的時間之間,少倍possib le,根據需要擴展