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>
- // [] 任意匹配
- 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("dfdfdfd"));
- // 连字符 -
- const reg1 = /0-9/;//匹配数字
- const reg2 = /a-z/;//匹配小写英文字母
- const reg3 = /A-Z/;//匹配大写英文字母
- const reg4 = /a-zA-Z0-9_/; //匹配英文字母+数字+下划线
- // ^ 取反
- // const reg6 = /[^0-9]/;
- const reg6 = /\d/;
- console.log(reg6.test("aaa"));
- // . 除换行以外的任意字符
- const reg7 = /./;
- console.log(reg7.test("aaa"));
- console.log(reg7.test("1234567890"));
- console.log(reg7.test(""));// false
- console.log(reg7.test("\n"));
- console.log(reg7.test("\r"));
- </script>
- </body>
- </html>
|