|
|
@@ -0,0 +1,50 @@
|
|
|
+<!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 = /[abc]/;
|
|
|
+ // console.log(reg.test("ababab"))
|
|
|
+ // console.log(reg.test("abc"))
|
|
|
+ // console.log(reg.test("acacac"))
|
|
|
+ // console.log(reg.test("acbbca"))
|
|
|
+ // console.log(reg.test("dds"))
|
|
|
+
|
|
|
+ // - 连字符
|
|
|
+ // const reg1 = /0-9/;
|
|
|
+ // const reg2 = /a-z/;
|
|
|
+ // const reg3 = /A-Z/;
|
|
|
+ // const reg4 = /a-zA-Z0-9_/;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * \w => /a-zA-Z0-9_/
|
|
|
+ * \d => /0-9/
|
|
|
+ * \W => /[^a-zA-Z0-9_]/
|
|
|
+ * \D => /[^0-9]/
|
|
|
+ */
|
|
|
+
|
|
|
+ // 取反
|
|
|
+ // const reg = /\D/;
|
|
|
+ // console.log(reg.test('212'))
|
|
|
+
|
|
|
+ // . 匹配换行外的任意字符
|
|
|
+ const reg = /./;
|
|
|
+ console.log(reg.test("aaa"))
|
|
|
+ console.log(reg.test("1234567897654"))
|
|
|
+ console.log(reg.test("")) // false
|
|
|
+ console.log(reg.test("\n"))
|
|
|
+ console.log(reg.test("\r"))
|
|
|
+ console.log(reg.test("\f"))
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|