`
Donald_Draper
  • 浏览: 981242 次
社区版块
存档分类
最新评论

js-repalace&Regexp

    博客分类:
  • HTML
阅读更多
<html>
<head>
<script type="text/javascript">
var time = "2016-04-25 14:05:45";
//time 需要重新赋值
time = time.replace(/[\s-:]/g,"");
//time = time.replace(new RegExp("[\s-:]","g"),"");
alert("replace:"+time);
//RegExp
var timer = "2016-04-25 14:05:45";
var timeRegExp = new RegExp("(^\\d{4})-(\\d{2})-(\\d{2})\\s{1}(\\d{2}):(\\d{2}):(\\d{2})$");
//var timeRegExp = new RegExp("(^\d{4})");
var result = timeRegExp.test(timer);
alert("result:"+result);
time=RegExp.$1+RegExp.$2+RegExp.$3+RegExp.$4+RegExp.$5+RegExp.$6;
//time=RegExp.$1;
alert("regExp:"+time);
/////////////////////////
var s = '我正在使用卡卡网www.webkaka.com来测试网站速度';
//var s = s.replace(/([\s\S]*)卡卡网([a-z.]*)([\s\S]*)/ig,'$2');
//alert("replace:"+s);

var words = '卡卡网';
var regExp=new RegExp("([\s\S]*)"+words+"([a-z.]*)([\s\S]*)","gmi");
regExp.test(s);
var url = RegExp.$2;
alert("url:"+url);
</script>
</head>
<title>test</title>
<body>
床前明月光,<br/>
疑是地上霜;<br/>
举头望明月,<br/>
低头思故乡。<br/>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics