|
@@ -0,0 +1,30 @@
|
|
|
|
|
+<!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 reg = /西游记/g;
|
|
|
|
|
+ var str = '西游记是四大名著之一,我爱看西游记';
|
|
|
|
|
+ console.log(reg.test(str));
|
|
|
|
|
+ console.log(reg.exec(str));
|
|
|
|
|
+ console.log(str.match(reg));
|
|
|
|
|
+ const str1 = str.replace(reg,'红楼梦');
|
|
|
|
|
+ console.log(str1);
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 正则定义
|
|
|
|
|
+ * const reg<名字> = /需要校验的规则/
|
|
|
|
|
+ * 1.test() 匹配文本中是否包含校验的字符 返回布尔值
|
|
|
|
|
+ * 2.exec() 返回数组格式 查找符合条件的字符
|
|
|
|
|
+ * 3.match() 查找符合规则的字符并返回
|
|
|
|
|
+ * 4.replace() 替换
|
|
|
|
|
+ */
|
|
|
|
|
+ </script>
|
|
|
|
|
+</body>
|
|
|
|
|
+
|
|
|
|
|
+</html>
|