如何用正则为文本里面的行添加数据
类似如下结构的数据:10,Rigid ANC
4(OPE),-1677,-1356,-6495,8251,-7712,970,-0.000,-0.000,-0.000
5(OPE),-1693,-1334,-6491,8137,-7815,993,-0.000,-0.000,-0.000
24(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
25(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
70,Prog DesignVSH
4(OPE),0,0,-1711,0,0,0,-31.880,-13.838,18.933
5(OPE),0,0,-1713,0,0,0,-32.468,-13.020,18.811
24(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603
25(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603
要在4(OPE), 5(OPE),24(SUS), 25(SUS)前面添加前面的只有两列的行的数字,变为如下:
10,Rigid ANC
10,4(OPE),-1677,-1356,-6495,8251,-7712,970,-0.000,-0.000,-0.000
10,5(OPE),-1693,-1334,-6491,8137,-7815,993,-0.000,-0.000,-0.000
10, 24(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
10,25(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
70,Prog DesignVSH
70,4(OPE),0,0,-1711,0,0,0,-31.880,-13.838,18.933
70,5(OPE),0,0,-1713,0,0,0,-32.468,-13.020,18.811
70,24(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603
70, 25(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603
请问用正则如何实现呢? 正则没弄。$FHD=FileOpen("ttt.txt")
$txt=""
While 1
$lin=FileReadLine($FHD)
If @error Then ExitLoop
$txt=$txt&$lin&@CRLF
$TEST=StringRegExp($lin,",",3)
If UBound($TEST)=1 Then
For $i=1 To 4
$lins=FileReadLine($FHD)
$txt=$txt&" "&StringLeft($lin,StringInStr($lin,","))&StringStripWS($lins,3)&@CRLF
Next
EndIf
WEnd
FileClose($FHD)
MsgBox(0,0,$txt)
页:
[1]