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>
- // 单词边界 \b
- // const reg = /\bcat\b/g;
- // const str = 'This is a cat it is a scattered';
- // console.log(str.replace(reg,'dog'))
- // ^ 匹配字母行首
- // const reg = /^ac/i;
- // console.log(reg.test('acc'))
- // console.log(reg.test("bca"))
- // console.log(reg.test("Abca"))
- // $ 匹配字母行尾
- // const reg = /c$/;
- // console.log(reg.test('ccc'))
- // console.log(reg.test(''))
- // console.log(reg.test('cb'))
- // console.log(reg.test('ac'))
- const reg = /^a$/;
- console.log(reg.test('a a'))
- console.log(reg.test(''))
- console.log(reg.test('aba'))
- console.log(reg.test('bbb'))
- </script>
- </body>
- </html>
|