aardio的string库中已经内置了模式匹配的功能函数,使用起来很简单.在做http.get() http.post()类的网页DOM模拟操作或自动营销软件时,大多会使用到提取网页源码中特定文本的功能.比如判断登陆是否成功,错误提示等.下面演示最简单的提取源码中的某一段,相当于 取文本中间() ,源码如下:
import console;
var strTestText = /*************
<input id="CaptchaDeText" name="CaptchaDeText" type="hidden" value="0d5a671ba8de4da8989550e20e28bf2b" />
*************/;
var pattern = //<@<input id="CaptchaDeText" name="CaptchaDeText" type="hidden" value="@>(.*?)<@" />@>
str = string.match(strTestText,pattern)
console.log("取出的value是" ,str );
console.pause(true);
string.match()的作用是按规则把需要的内容从文本中匹配出来,相当于 取文本中间()
模式匹配中,括号的作用是分组捕获,即是只返回括号里的内容,<@ @>标签的作用是局部禁用,方便里面有转义字符特殊字符时使用.