源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <script> // 使用 \b 进行单词匹配 var patternWord = /\bword\b/; var textWord = 'This is a word in a sentence.'; if (patternWord.test(textWord)) { document.write('找到匹配的单词:', patternWord.exec(textWord)[0]); } else { document.write('没有找到匹配的内容!'); } </script> </body> </html>
运行结果: