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