1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <!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 reg1 = /[^0-9]/
- console.log(reg1.test("1111"))
- console.log(reg1.test("abc"))
- // . 除换行外的任意字符
- const reg = /./
- console.log(reg.test(''))//. 匹配空字符串是false
- console.log(reg.test('abc'))
- console.log(reg.test('\n'))
- console.log(reg.test('\r'))
- console.log(reg.test('34567'))
- </script>
- </body>
- </html>
|