Open In App

Lodash _.isRegExp() Method

Last Updated : 04 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Lodash _.isRegExp() method is used to find whether the given value is a regular expression or not. It returns True if the given value is a regular expression. Otherwise, it returns false.  

Syntax:

_.isRegExp(value);

Parameters:  

  • value: This parameter holds the value to check. 

Return Value:

  • This method returns true if the value is a regular expression, else false.

Example 1: In this example, we are passing a regular expression to the lodash _.isRegExp() method. the object starts and ends with ‘/’, therefore it is a regular expression. Hence, the result is true. 

javascript
// Requiring the lodash library  
const _ = require("lodash");

// Use of _.isRegExp() method 
console.log(_.isRegExp(/gfg/)); 

Output:

true

Example 2: In this example, we are passing a string to the _.isRegExp() function Since a string is not a regular expression, the output will be false.  

javascript
// Requiring the lodash library  
const _ = require("lodash");

// Use of _.isRegExp() method 
console.log(_.isRegExp('gfg')); 

Output:

false

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.


Similar Reads