1234567891011121314151617181920212223242526272829303132333435363738 |
- <!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>
- // [] 任意匹配
- var reg = /[abc]/;
- console.log(reg.test("abc"));
- console.log(reg.test("acd"));
- console.log(reg.test("aiu"));
- console.log(reg.test("cud"));
- console.log(reg.test("bhd"));
- console.log(reg.test("uul"));
- // - 连字符
- const reg1 = /a-z/;//匹配小写26个字母
- const reg2 = /A-Z/;//匹配大写26个字母
- const reg3 = /0-9/;//匹配数字
- const reg4 = /a-zA-Z0-9_/;//匹配密码:英文+数字+_
- // ^ 取反 不在范围内
- const reg5 = /[^0-9]/;
- console.log(reg5.test('0909'));
- console.log(reg5.test('aaa'));
- // . 除换行符外的任意字符
- // 换行符 \n \r
- const reg6 = /./;
- console.log(reg6.test("aaa"));
- console.log(reg6.test(""));// 空字符串是false
- console.log(reg6.test("1124"));
- console.log(reg6.test("\n"));
- console.log(reg6.test("??"));
- console.log(reg6.test("\r"));
- </script>
- </body>
- </html>
|