A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-regexp-test-method/ below:

JavaScript RegExp test() Method - GeeksforGeeks

JavaScript RegExp test() Method

Last Updated : 11 Jul, 2025

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.

JavaScript
const pattern = /hello/;
const text = "hello world";

console.log(pattern.test(text));
Syntax
RegExpObject.test(str)

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

Example 1: Searching for the string "computer" in the original string.  

JavaScript
let str = "GeeksforGeeks : A computer science portal for geeks.";
let regex = new RegExp("computer",);
let rex = regex.test(str);

console.log(rex);

Example 2: Searching for the string "GEEK" in the original string. 

JavaScript
let str = "GeeksforGeeks: A computer science portal for geeks.";
let regex = new RegExp("GEEK",);
let rex = regex.test(str);

console.log(rex);
Supported Browsers

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.  



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4