123456789101112131415161718192021222324252627282930313233 |
- <!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>
- // 1. \b 单词边界
- const reg1 = /\ban\b/ig;
- const str1 = "1an Apple,An2 orange";
- console.log(str1.match(reg1));
- // 2.^ 匹配字母首行
- const reg2 = /^an/ig;
- const str2 = "an1 Apple, An2 orange an";
- console.log(str2.match(reg2));
- // 3.$ 匹配字母尾行
- const reg3 = /an$/ig;
- const str3 = "an1 Apple, An3 orange an";
- console.log(str3.match(reg3));
- const reg4 = /^a$/ig;
- // const str4 = "an1 Apple, An3 orange an";
- console.log(reg4.test('aaa'));
- console.log(reg4.test('a'));
- console.log(reg4.test(' '));
-
- </script>
- </body>
- </html>
|