正则表达式 有效类[:class:]无法匹配----[已解决]
本帖最后由 superflq 于 2010-3-1 08:33 编辑刚开始研究正则表达式,有很多不理解,望大大们多多指点
[:class:]
在字符的给定类中匹配字符. 有效类是:
alpha (任何字母字符), alnum (任何字母数字字符), lower (任何小写字母),
upper (任何大写字母), digit (任何十进制数字 0-9), xdigit (任何十六进制数字, 0-9, A-F, a-f),
space (任何空白字符), blank (只有一个空格或制表符), print (任何可打印字符),
graph (除空格外的任何可打印字符), cntrl (任何控制字符 )
punct (任何标点字符). 因此 相当于 [[:digit:]].
[^:class:]在类中除第一个字符外,不匹配任何字符
根据有效类的说明[:xdigit:]应该是可以匹配 任何十六进制的字符,但是根据程序来看[^:xdigit:]才是可以匹配十六进制表达式
下面是代码,和结果截图
$text_in = "C1CfgGh"
$text_out1 = StringRegExpReplace($text_in, "([:xdigit:]{2})([:xdigit:]{2})", "$1+$2+")
$text_out2 = StringRegExpReplace($text_in, "([^:xdigit:]{2})([^:xdigit:]{2})", "$1+$2+")
$text_out3 = StringRegExpReplace($text_in, "({2})({2})", "$1+$2+")
MsgBox(0, "正则替换", "([:xdigit:]{2})([:xdigit:]{2})表达式结果为:"&$text_out1 _
& @CRLF& @CRLF & "([^:xdigit:]{2})([^:xdigit:]{2})表达式结果为:"&$text_out2 _
& @CRLF& @CRLF &"({2})({2})表达式结果为:"&$text_out3)
$text_in2 = "1234Gh"
$text_out1 = StringRegExpReplace($text_in2, "([:digit:]{2})([:digit:]{2})", "$1+$2+")
$text_out2 = StringRegExpReplace($text_in2, "([^:digit:]{2})([^:digit:]{2})", "$1+$2+")
$text_out3 = StringRegExpReplace($text_in2, "({2})({2})", "$1+$2+")
MsgBox(0, "正则替换", "([:digit:]{2})([:digit:]{2})表达式结果为:"&$text_out1 _
& @CRLF& @CRLF & "([^:digit:]{2})([^:digit:]{2})表达式结果为:"&$text_out2 _
& @CRLF& @CRLF &"({2})({2})表达式结果为:"&$text_out3)
确实是AU3 正则的问题还是,我的表达式有问题,请高手指教 注意表达式写法,[:xdigit:] 应该是 [[:xdigit:]]$text_in = "C1CfgGh"
$text_out1 = StringRegExpReplace($text_in, "([[:xdigit:]]{2})([[:xdigit:]]{2})", "$1+$2+")
$text_out2 = StringRegExpReplace($text_in, "([^:xdigit:]{2})([^:xdigit:]{2})", "$1+$2+")
$text_out3 = StringRegExpReplace($text_in, "({2})({2})", "$1+$2+")
MsgBox(0, "正则替换", "([[:xdigit:]]{2})([[:xdigit:]]{2})表达式结果为:" & $text_out1 _
& @CRLF & @CRLF & "([^:xdigit:]{2})([^:xdigit:]{2})表达式结果为:" & $text_out2 _
& @CRLF & @CRLF & "({2})({2})表达式结果为:" & $text_out3)
$text_in2 = "1234Gh"
$text_out1 = StringRegExpReplace($text_in2, "([[:digit:]]{2})([[:digit:]]{2})", "$1+$2+")
$text_out2 = StringRegExpReplace($text_in2, "([^:digit:]{2})([^:digit:]{2})", "$1+$2+")
$text_out3 = StringRegExpReplace($text_in2, "({2})({2})", "$1+$2+")
MsgBox(0, "正则替换", "([[:digit:]]{2})([[:digit:]]{2})表达式结果为:" & $text_out1 _
& @CRLF & @CRLF & "([^:digit:]{2})([^:digit:]{2})表达式结果为:" & $text_out2 _
& @CRLF & @CRLF & "({2})({2})表达式结果为:" & $text_out3) 谢谢楼上,学习了~:face (36):
页:
[1]