代码-JS之使用正则对象的成员
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
/********* 使用正则对象的成员方式一 *********/
var str1 = "php phhp";
var r1 = /ph+p/;
var result1 = r1.exec(str1);
console.log(result1);
/********* 使用正则对象的成员方式二 *********/
//var r = new RegExp(正则表达式[//写法], 修饰符[字符串类型]);
var str2 = "phP Phhhp";
var r2 = new RegExp(/ph+p/, 'i');
var result2 = r2.exec(str2);
console.log(result2);
/********* 使用正则对象的成员方式三 *********/
//var r = new RegExp(正则表达式[字符串类型], 修饰符[字符串类型]);
var str3 = "php phhp phhhp";
var r3 = new RegExp('(p)h+\\1', 'g');
var result3 = r3.exec(str3);
console.log(result3);
</script>
</body>
</html>
Copyright [2018] by [羊驼可以吃吗] form [https://www.cnblogs.com/phpisfirst/]