首页 > 编程语言 > 详细

javascript对象Math和正则对象

时间:2020-01-29 19:41:54      阅读:68      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>正则对象</title>
</head>
<body>
<script>
//1.匹配方式一
// var re_obj=new RegExp(‘\d+‘,‘g‘);//g 为一种全局模式
// alert(re_obj.test(‘dajsasj5613ss‘));//true
//2.匹配方式二
// var re_obj=/\d+/g;
// alert(re_obj.test(‘sddhdj852sss51‘));//true
//3.取出匹配的内容
var reg=‘asdfltxstar1997xing315‘
// alert(reg.match(/\d/g));//1,9,9,7,3,1,5 取出所有匹配的内容放到数组里
// alert(reg.match(/\d+/g));//1997,315
// alert(reg.search(/\d+/g));//11 取出第一个结果的索引值
// alert(reg.split(/\d+/g));//asdfltxstar,xing,
alert(reg.replace(/\d+/g,‘*‘));//asdfltxstar*xing*
// ------------------------------------------------------
//Math对象
// alert(Math.random())//(0,1)
// alert(Math.round(2.6))//3
alert(Math.pow(2,4))//16


</script>

</body>
</html>

javascript对象Math和正则对象

原文:https://www.cnblogs.com/startl/p/12240985.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!