123456789101112131415161718192021222324252627282930313233343536 |
- <!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]/ //任意匹配abc
- // console.log(reg.test('abc'))
- // console.log(reg.test('abandon'))
- // console.log(reg.test('banana'))
- // console.log(reg.test('car'))
- // console.log(reg.test('listen'))
- // console.log(reg.test('tomorrow'))
- // 连字符
- // const reg1 = /[a-z]/;//a-z的26个字母任意匹配
- // const reg2 = /[A-Z]/; //A-Z的26个字母任意匹配
- // const reg3 = /[0-9]/; //0-9的数字任意匹配
- // const reg4 = /[a-zA-Z0-9_]/
- // . 除换行外的任意字符
- const reg = /./
- console.log(reg.test(''))
- console.log(reg.test('abc'))
- console.log(reg.test('\n'))
- console.log(reg.test('\r'))
- console.log(reg.test('34567'))
- </script>
- </body>
- </html>
|