用一句正则替换将数字后面加一个0[已解决]
本帖最后由 superflq 于 2010-11-12 15:29 编辑我有ini格式的文件
里面有
a = 1
b = 2
c = 3
a = 44
"b = 55
c = 66
a = 777
b = 888
c = 999
我想把其中的“a =”后面的数字乘以10,但是考虑到乘以10比较难实现,就像了个办法在这个数字后面加一个0,变成
a = 10
b = 2
c = 3
a = 440
"b = 55
c = 66
a = 7770
b = 888
c = 999
不知道有没高手有办法$a = "a = 1" & @CRLF & _
"b = 2" & @CRLF & _
"c = 3" & @CRLF & _
"a = 44" & @CRLF & _
"b = 55" & @CRLF & _
"c = 66" & @CRLF & _
"a = 777" & @CRLF & _
"b = 888" & @CRLF & _
"c = 999"
$b = StringRegExpReplace($a,
MsgBox(0,0,$b)
;用一句正则替换
;让结果
#CS
$b = "a = 10" & @CRLF & _
"b = 2" & @CRLF & _
"c = 3" & @CRLF & _
"a = 440" & @CRLF & _
"b = 55" & @CRLF & _
"c = 66" & @CRLF & _
"a = 7770" & @CRLF & _
"b = 888" & @CRLF & _
"c = 999"
#CE
;就是说要把“a = ”后面的数字后面加一个0
;这个问题纠结了我好久了,有没高手可以帮忙解决下 Local $Str = _
'a = 1' & @CRLF & _
'b = 2' & @CRLF & _
'c = 3' & @CRLF & _
'a = 44' & @CRLF & _
'b = 55' & @CRLF & _
'c = 66' & @CRLF & _
'a = 777' & @CRLF & _
'b = 888' & @CRLF & _
'c = 999'
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExpReplace($str, '(?<=\n|^)(a\h*=.*\d+)', '${1}0', 0)
MsgBox(0, '替换结果', $Test)
afan 发表于 2010-11-12 14:30 http://www.autoitx.com/images/common/back.gif
超版果然,无敌,好好研究研究 "以解决"有错别字… _ _|| "以解决"有错别字… _ _||
afan 发表于 2010-11-12 14:36 http://www.autoitx.com/images/common/back.gif
'${1}0'不明白为什么这里是这么用的,一般不是 $1的么, $1后面加0不成$10了?为了区别,必须加{} (?<=\n|^)(a\h*=.*\d+)
这个里面的\h是什么东东,好像没见过这个么 \h 水平空白符,这里就是匹配空格。 谢谢超版解答~{:face (356):}
页:
[1]