|
@@ -0,0 +1,24 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <script>
|
|
|
+ // 正则
|
|
|
+ // 定义:const 字段名 = /需要校验的规则/
|
|
|
+ const reg = /西游记/g;
|
|
|
+ const str1 = '西游记,四大名著中有西游记';
|
|
|
+ // 1.test 匹配文本中是否包含校验的字段 返回布尔值
|
|
|
+ console.log(reg.test(str1));
|
|
|
+ // 2.exec 返回数组格式 查找符合规则的字符
|
|
|
+ console.log(reg.exec(str1));
|
|
|
+ // 3.replace 替换指定字符
|
|
|
+ console.log(str1.replace(reg,'红楼梦'));
|
|
|
+ // 4.match 查找字符串中符合规则的字符
|
|
|
+ console.log(str1.match(reg));
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|