javascript

RegExp Object and Methods


The RegExp object is a built-in object used for working with regular expressions. Regular expressions are patterns used to match character combinations in strings. The RegExp object allows you to create regular expression patterns, perform searches within strings based on these patterns, and extract or replace matching substrings. It provides methods and properties to work with regular expressions effectively.

 

Methods of RegExp Objects are:

 

1.  `test()`: This method checks if a pattern exists in a string, returns true or false.

 

Syntax:

regex.test("string");

 

2.  `exec()`: This method returns an array containing all matched groups or null if there are no matches.

 

Syntax:

regex.exec("string");