搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JavaScript基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JavaScript 正则表达式多行搜索示m例 - 基础教程(div.cn)</title> <body> <p>单击此按钮,在字符串的每一行的开头进行多行搜索"to":</p> <button onclick="myFunc()">Click</button> <p id="output"></p> <script> function myFunc() { var str = "The question is \nto be, or not \nto be"; var patt = /to/m; var res = str.match(patt); document.getElementById("output").innerHTML = res; } </script> </body> </html>
运行结果