js正则匹配

var text = "testing: 1, 2, 3";
var pattern = /\d+/g;
pattern.test(text) //=>true :匹配成功
text.search(pattern);//=> 9:首次匹配成功的位置(从0开始计数)
text.match(pattern);//=>["1", "2", "3"]:所有匹配组成的数组
text.replace(pattern, '#');//=>"testing: #, #, #"
text.split(/\D+/);// => ["", "1", "2", "3"]:用非数字字符截取字符串

posted @ 2015-03-10 11:18  黑面骑士  阅读(178)  评论(0)    收藏  举报