每个容器的ID由4个字和7位数字组成(在EDI文件中-之间没有空格。)
在代码处,还有与表达式匹配的11位数字的字符串。
表达式的形式为:
(\w{4}\d{7})
由于字母和数字,这不能完全解决匹配问题。
演示链接:https://regex101.com/r/vwH9nH/4
另一个更接近匹配的表达式是:
([A-Z]{4}d{7})
似乎更接近于此,但与notepad ++不匹配,无法表示容器的ID。
在记事本++中,我尝试:
(([A-Z]{4}d{7})h*|(?s:.)
定义的容器ID
(?1$1\n:)
UNB+UNOA:2+RCW OPS CENTER+TERMINAL+180808:1519+1533741570C3ED+++++RCW OPS CENTER'UNH+01533741570BAP+BAPLIE:D:95B:UN:SMDG22'BGM++CAPSTAN4.20180808151930+9'DTM+137:1808081519UTC:301'TDT+20+081S+++HSD:172:166+++9V7575:103:ZZZ:MONTE VERDE'LOC+5+BRSSA:139:6'LOC+61+COCTG:139:6'DTM+178:1808090412:201'DTM+133:1808091512:201'DTM+132:1808180041:201'RFF+VON:081N'LOC+147+0380412::5'MEA+WT++KGM:29515'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+DOHAI:139:6'RFF+BM:1'EQD+CN+SUDU8505087+45G1+++5'NAD+CA+HSD:172:20'LOC+147+0380312::5'MEA+WT++KGM:29586'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+DOCAU:139:6'RFF+BM:1'EQD+CN+UACU5363691+45G1+++5'NAD+CA+HLC:172:20'LOC+147+0380212::5'MEA+WT++KGM:29591'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+COCTG:139:6'RFF+BM:1'EQD+CN+TGHU9702812+45G1+++5'NAD+CA+MSC:172:20'LOC+147+0380112::5'MEA+WT++KGM:29616'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+DOCAU:139:6'RFF+BM:1'EQD+CN+HLXU6240079+45G1+++5'NAD+CA+HLC:172:20'LOC+147+0380414::5'MEA+WT++KGM:29476'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+PRSJU:139:6'RFF+BM:1'EQD+CN+HASU4556735+45G1+++5'NAD+CA+HSD:172:20'LOC+147+0380314::5'MEA+WT++KGM:29476'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+DOHAI:139:6'RFF+BM:1'EQD+CN+SUDU6787839+45G1+++5'NAD+CA+HSD:172:20'LOC+147+0380214::5'MEA+WT++KGM:29481'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+COCTG:139:6'RFF+BM:1'EQD+CN+TGHU9861619+45G1+++5'NAD+CA+MSC:172:20'LOC+147+0380114::5'MEA+WT++KGM:29492'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+COCTG:139:6'RFF+BM:1'EQD+CN+HASU5014810+45G1+++5'NAD+CA+HSD:172:20'LOC+147+0301582::5'MEA+WT++KGM:29123'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+COCTG:139:6'RFF+BM:1'EQD+CN+CLHU4693498+42G1+++5'NAD+CA+MSC:172:20'LOC+147+0301482::5'MEA+WT++KGM:29160'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+PECLL:139:6'RFF+BM:1'EQD+CN+TCLU4424005+42G1+++5'NAD+CA+HLC:172:20'LOC+147+0301382::5'MEA+WT++KGM:29183'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+COCTG:139:6'RFF+BM:1'EQD+CN+...
在这种匹配和替换中,我只有一个空行:
我想将所有容器都放在一列中。
我的预期输出是:
SUDU8505087
UACU5363691
TGHU9702812
HLXU6240079
HASU4556735
SUDU6787839
TGHU9861619
HASU5014810
CLHU4693498
TCLU4424005
答案 0 :(得分:0)
替换
.*?([A-Z]{4}\d{7})
作者
$1\n
并获得
SUDU8505087
UACU5363691
TGHU9702812
HLXU6240079
HASU4556735
SUDU6787839
TGHU9861619
HASU5014810
CLHU4693498
TCLU4424005
+42G1+++5'NAD+CA+HLC:172:20'LOC+147+0301382::5'MEA+WT++KGM:29183'LOC+9+BRSSA:139:6+TECSV'LOC+11+COCTG:139:6+TCC'LOC+83+COCTG:139:6'RFF+BM:1'EQD+CN+...
然后手动删除最后一行。
答案 1 :(得分:0)