|
@@ -0,0 +1,39 @@
|
|
|
+<!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>
|
|
|
+ // 1. 任意匹配 []
|
|
|
+ // const reg = /[abc]/;
|
|
|
+ // console.log(reg.test("ababab"));
|
|
|
+ // console.log(reg.test("abc"));
|
|
|
+ // console.log(reg.test("acbacb"));
|
|
|
+ // console.log(reg.test("acacac"));
|
|
|
+ // console.log(reg.test("dfdfdf"));
|
|
|
+
|
|
|
+ // 2.连字符 -
|
|
|
+ const reg1 = /[0-9]/;
|
|
|
+ const reg2 = /[a-z]/;
|
|
|
+ const reg3 = /[A-Z]/;
|
|
|
+ const reg4 = /[a-zA-Z0-9_]/;
|
|
|
+ console.log(reg1.test(4))
|
|
|
+
|
|
|
+ // 3.取反 ^
|
|
|
+ const reg5 = /[^0-9]/
|
|
|
+ console.log(reg5.test(4))
|
|
|
+
|
|
|
+ // 4. . 除空格外的任意字符
|
|
|
+ const reg6 = /./;
|
|
|
+ console.log(reg6.test("aaa"));
|
|
|
+ console.log(reg6.test("1234567890"));
|
|
|
+ console.log(reg6.test(""));
|
|
|
+ console.log(reg6.test("\n"));
|
|
|
+ console.log(reg6.test("\r"));
|
|
|
+
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|