js正则表达式test()和exec()用法
生活随笔
收集整理的這篇文章主要介紹了
js正则表达式test()和exec()用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<script type="text/javascript">
//正則.test(內容),返回true或false
function t1(){
?var con = document.getElementsByName('content')[0].value;//需要查找的內容
?var reg = /hi/;//需要匹配的內容
?alert(reg.test(con));
}
//正則.exec(內容),返回匹配的內容
function t2(){
?var con = document.getElementsByName('content')[0].value;//需要查找的內容
?var reg = /\bhi\w+/;//需要匹配的內容
?alert(reg.exec(con));
}
</script>
</head>
<body>
<textarea rows="5" cols="30" name="content"></textarea><br />
<button />
<button οnclick="t2();">正則測試(exec函數)</button>
轉載于:https://blog.51cto.com/10086844/1629569
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的js正则表达式test()和exec()用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: malloc的内存分配原理
- 下一篇: 第二次启用httpd24调用mysql时