haijie1223 发表于 2012-6-19 20:58:49

正则间隔替换[已解决]

本帖最后由 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.
谢谢!

afan 发表于 2012-6-19 21:43:07

早两天从 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)

zldfsz 发表于 2012-6-19 21:47:25

就是去掉下面两个字符串???
"ASC("
")"

haijie1223 发表于 2012-6-19 23:47:24

回复 3# zldfsz


    是的。。。

3mile 发表于 2012-6-20 11:14:26

回复 2# afan
ExpandVarStrings果然犀利

afan 发表于 2012-6-20 11:18:02

回复 5# 3mile


    是的,相当于变相的代入了“匹配”

afan 发表于 2012-6-20 18:18:30

就是去掉下面两个字符串???
"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)

haijie1223 发表于 2012-6-20 19:19:28

回复 7# afan


    A版把我的问题想复杂了,不过学到了更多的东西,真是好!
StringRegExpReplace($str, '(?i)Asc\((.+?)\)', '$1')
这一句中的正则和后面的替换,A版能讲解一下么,看不大明白。

haijie1223 发表于 2012-6-20 19:28:05

回复 7# afan


    再次谢谢A版,已经大体明白了。
页: [1]
查看完整版本: 正则间隔替换[已解决]