RegExp Constructor Properties

The RegExp constructor function has several properties and apply to all regular expressions.

Each property has a verbose property name and a shorthand name. The RegExp constructor properties are listed in the following table.

Verbose NameShort NameDescription
input$_The last string matched.
lastMatch $& The last matched text.
lastParen$+The last matched capturing group.
leftContext$`The text that appears in the input string prior to lastMatch.
multiline$*A Boolean value telling whether all expressions should use multiline mode.
rightContext$'The text that appears in the input string after lastMatch.
 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var text = "this is a test. This is another test."; 
        var pattern = /(.)est/g; 
        
        if (pattern.test(text)){ 
            document.writeln(RegExp.input); //this is a test. This is another test.
            document.writeln(RegExp.leftContext); //this is a
            document.writeln(RegExp.rightContext);//. This is another test.
            document.writeln(RegExp.lastMatch); //test
            document.writeln(RegExp.lastParen); //t
            document.writeln(RegExp.multiline); false
        } 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Essential Types  

REGEXP:
  1. The Regexp Type
  2. RegExp constructor
  3. RegExp Instance Properties
  4. RegExp's exec() does the matching.
  5. RegExp's test()
  6. RegExp's toLocaleString() and toString()
  7. RegExp Constructor Properties