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 Name | Short Name | Description |
---|---|---|
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>