Sunday, December 29, 2024
Google search engine
HomeLanguagesJavascriptJavaScript RegExp constructor Property

JavaScript RegExp constructor Property

The RegExp constructor in JavaScript is used to return the function that created the RegExp object’s prototype i.e. the construction function for an object. It returns the different references for various JavaScript types:

  • Regular Expression: The constructor property returns function RegExp() { [native code] } for regular expressions.
  • Numbers: The constructor property returns function Number() { [native code] } for JavaScript numbers.
  • Strings: The constructor property returns function String() { [native code] } for JavaScript strings.

Syntax:  

RegExpObject.constructor

Example 1: This example returns the type of constructor on variable regex.  

Javascript




function RegExpConstructor() {
    let regexp = new RegExp("e{2, }", "gi");
    let rex = regexp.constructor;
     
    console.log("Constructor: " + rex);
}
 
RegExpConstructor();


Output

Constructor: function RegExp() { [native code] }

Example 2: This example returns the type of constructor on variable match4. 
 

Javascript




function RegExpConstructor() {
    const str = "GeeeeK@128";
    let regex4 = new RegExp("e{2, }", "gi");
    let replace = "$";
    let match4 = str.replace(regex4, replace);
    let rx = match4.constructor;
     
    console.log("Constructor: " + rx);
}
 
RegExpConstructor();


Output

Constructor: function String() { [native code] }

Supported Browsers: The browsers supported by RegExp constructor are listed below: 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 5 and above
  • Safari 1 and above

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.  

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments