正则间隔替换[已解决]
本帖最后由 haijie1223 于 2012-6-20 19:28 编辑Local $str1 = Asc("A") & "," & Asc("B") & "," & Asc("C") & "," & Asc("D") & "," & Asc("E") & "," & Asc("F") & "," & Asc("G") & "," & Asc("H")
MsgBox(0, "", $str1)
Local $str2 = "A" & "," & "B" & "," & "C" & "," & "D" & "," & "E" & "," & "F" & "," & "G" & "," & "H"
MsgBox(0, "", $str2)
如题:想用正则替换的方法,使得$str1得到$str2.
谢谢! 早两天从 Duvet 大师那学到的~ ExpandVarStringsLocal $str1 = '', $str2
For $i = Asc('A') To Asc('H')
$str1 &= $i & ','
Assign('___' & $i, Chr($i))
Next
$str1 = StringTrimRight($str1, 1) ;得到测试字符串及同时增加了申明
Opt('ExpandVarStrings', 1)
$str2 = StringRegExpReplace($str1, '\d+', '$___\0$')
MsgBox(0, $str1, $str2) 就是去掉下面两个字符串???
"ASC("
")" 回复 3# zldfsz
是的。。。 回复 2# afan
ExpandVarStrings果然犀利 回复 5# 3mile
是的,相当于变相的代入了“匹配” 就是去掉下面两个字符串???
"ASC("
")"
zldfsz 发表于 2012-6-19 21:47 http://www.autoitx.com/images/common/back.gif
回复zldfsz
是的。。。
haijie1223 发表于 2012-6-19 23:47 http://www.autoitx.com/images/common/back.gif
晕,完全不是一个概念…Local $Str = 'Asc("A") & "," & Asc("B") & "," & Asc("C") & "," & Asc("D") & "," & Asc("E") & "," & Asc("F") & "," & Asc("G") & "," & Asc("H")' & @CRLF
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExpReplace($str, '(?i)Asc\((.+?)\)', '$1')
MsgBox(0, '替换结果', $Test)
回复 7# afan
A版把我的问题想复杂了,不过学到了更多的东西,真是好!
StringRegExpReplace($str, '(?i)Asc\((.+?)\)', '$1')
这一句中的正则和后面的替换,A版能讲解一下么,看不大明白。 回复 7# afan
再次谢谢A版,已经大体明白了。
页:
[1]