What is RegExp Object in JavaScript ?
Last Updated :
15 Feb, 2024
In JavaScript, the RegExp
object is a built-in object used to represent regular expressions, which are patterns used to match character combinations in strings. Regular expressions are powerful tools for searching, replacing, and extracting text based on specific patterns.
Syntax:
/pattern/modifiers;
Example: Below is an example of RegExp.
Javascript
const pattern = /hello/;
const dynamicPattern = new RegExp( "world" );
console.log(pattern.test( "hello world" ));
console.log(dynamicPattern.exec( "hello world" ));
|
Output
true
[ 'world', index: 6, input: 'hello world', groups: undefined ]
Share your thoughts in the comments
Please Login to comment...