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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。