码迷,mamicode.com
首页 > Web开发 > 详细

js正则匹配

时间:2015-03-10 11:45:53      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

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"]:用非数字字符截取字符串

js正则匹配

标签:

原文地址:http://www.cnblogs.com/jiaxu/p/4325454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!