<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//1.方式1:使用字面量方式创建对象
var reg = /xinlang/;
var str = 'fsafafasfxinlangfafafa';
//检验字符是否匹配正则表达式,用test()
var boo = reg.test(str);
console.log(boo);
//2.方式2:使用构造函数方式创建对象
var reg2=new RegExp('zhangsan');
var str='dasfasgfasfzhangsanfafa';
var boo2=reg2.test(str);
console.log(boo2);
//3.正则表达式参数g-全局匹配,i-忽略大小写,m-多行匹配
var reg3 = /zhanGsan/gi;
// var reg3 = new RegExp('zhangsan','g');
var str3 = '11111111zhangsan2132314141zhangsan';
var newStr3 = str3.replace(reg3, '张三');
console.log(newStr3);
</script>
</body>
</html>