正则表达式看过去看过来,还是一个糊涂。
其实学习正则表达式最好的办法就是练习中学习。
dos里面的 findstr就是正则表达式搜索。vbs里也有。
下面的小程序就是vbs编写的学习软件。
只选用了正则表达式的全局属。什么是全局属下?你用了就知道了。
我在这里说是空谈。
还有在哪里看正则表达式的规则?dos的findstr /?
我可以说,用了包你10分钟明白什么是正则表达式。
变生奥为浅显。
复制下面的代码,保存为regtest.vbs 就ok了。 | | | ''''************正则表达式练习小程序 作者 myzam 2011-2-26******* | | '''''特别说明:只能在cmd中运行,否则报错。 | | '''''运行语法:“cscript+脚本”。 | | '''''又注,vbs中\b,和dos中的\<,\>相当,表示一个单词 | | ''''(如word,ath,中国,0852等)的起点和终点。 | | '''''这是全局设置的正则表达式,我用x作为替代了。 | | set oreg=new regexp | | | | wscript.echo "请输入字符串:" | | str=wscript.stdin.readline | | | | wscript.echo "请输入正则表达式:" | | oreg.pattern=wscript.stdin.readline | | oreg.global=true '这里设置的是全局属性 | | set matches=oreg.execute(str) | | wscript.echo oreg.replace(str,"x") | | for matche=o to matches.count-1 | | wscript.echo "index= "&matche,"-------value= "&matches(matche) | | next | | | | ''''''''======================================== | | '''附测试题 | | '''' 字符串为: the thecome comethecome | | '''' 模板为:the | | '''''===========================================COPY |
[ 本帖最后由 myzam 于 2011-2-26 21:56 编辑 ] |