Thursday, September 4, 2025
HomeLanguagesJavascriptJavaScript RegExp test() Method

JavaScript RegExp test() Method

The RegExp test() Method in JavaScript is used to test for match in a string. If there is a match this method returns true else it returns false.

Syntax: 

RegExpObject.test(str)

Where str is the string to be searched. This is required field.

Example 1: This example searches for the string “computer” in the original string.  

Javascript




function geek() {
    let str = "neveropen is the computer science"
        + " portal for neveropen.";
    let regex = new RegExp("computer",);
    let rex = regex.test(str);
 
    console.log(rex);
}
geek()


Output

true

Example 2: This example searches for the string “GEEK” in the original string. 

Javascript




function geek() {
    let str = "neveropen is the computer science"
        + " portal for neveropen.";
    let regex = new RegExp("GEEK",);
    let rex = regex.test(str);
 
    console.log(rex);
}
geek()


Output

false

Supported Browsers: The browsers supported by RegExp test() Method are listed below: 
 

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Edge

We have a complete list of Javascript RegExp expressions, to check those please go through this JavaScript RegExp Complete Reference article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.  

RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS