JavaScript test() 方法


html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鳥教程(runoob.com)</title>
</head>
<body>

<script>
var str="Hello world!";
//查找"Hello"
var patt=/Hello/g;
var result=patt.test(str);
document.write("返回值: " +  result); 
//查找 "Runoob"
patt=/Runoob/g;
result=patt.test(str);
document.write("<br>返回值: " +  result);
</script>
    
</body>
</html>

 

 

定義和用法

test() 方法用於檢測一個字符串是否匹配某個模式.

如果字符串中有匹配的值返回 true ,否則返回 false。

語法

RegExpObject.test( string)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM