码迷,mamicode.com
首页 > 其他好文 > 详细

正则小记

时间:2017-05-18 17:26:02      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:new   pre   替换   方法   asc   mat   attr   highlight   att   

取出字符串“10px”里的“10”大概有三种方法

var str="10px";
/\d+/.exec(str);//方法一,用的是正则对象的方法exec
str.match(/\d+/));//方法二,用的是字符串对象的方法match
str.replace(/px/,"");//方法三,把px替换成空,用的是字符串对象的方法replace

直接量语法

/pattern/attributes

创建 RegExp 对象的语法:

new RegExp(pattern, attributes);


很明显直接量语法爽歪歪

正则小记

标签:new   pre   替换   方法   asc   mat   attr   highlight   att   

原文地址:http://www.cnblogs.com/qdog/p/6874420.html

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