JS正则
test -判断字符串是否符合规定的正则
例:
var rep = /d+/ 注:javascript正则表达式格式为/../
rep.test("dfafadfadf552dfdafds")结果为true
exec -获取匹配的数据
rep = /d+/
str = "jsafkajf27fdf56"
rep.exec(str)结果为27
var str = "JavaScript is more fun than others"
var pattern = /Java(w+)/;
pattern.exec(str)结果为["JavaScript","Script"]
var str = "JavaScript is Java fun than Javaweb"
var pattern = /Java(w+)/g;加上字母g表示全局匹配(/../匹配正则表达式;/../m表示多行匹配(默认情况下不写/m也表示多行匹配;//i不区分大小写))
pattern.exec(str)
执行第一次结果为["JavaScript","Script"]
执行第二次结果为["Java"]
执行第三次结果为["JavaWeb","Web"]