var pattern1 = /好/g; console.log(pattern1.test("你好"));
字符串查找:
var pattern1 = /w/;
console.log(pattern1.test("njkhjkjk"));
空格查找:
var pattern1 = /s/;
console.log(pattern1.test("njkhjkjk"));
查找 页面中有几个人字:
var re = "人中人人人人", rex = /中/g, ary = rex.exec(re), i = 0; while(ary){ i++; ary = rex.exec(re); } console.log(i);
查找“.”后面的文字
var str = "a.swf", reg = /./, temp = ""; if(reg.test(str)){ temp = RegExp.rightContext; } console.log(temp);