RegExp

Moduleejs
Definitionfinal class RegExp
InheritanceRegExp inherit Object
Specifiedevolving

Regular expressions per ECMA-262.

The following special characters are supported:

\\Reverse whether a character is treated literally or not.
^Match to the start of input. If matching multiline, match starting after a line break.
\Match to the end of input. If matching multiline, match before after a line break.
* Match the preceding item zero or more times.
+Match the preceding item one or more times.
?Match the preceding item zero or one times.
(mem)Match inside the parenthesis (i.e. "mem") and store the match.
(?:nomem)Match "nomem" and do not store the match.
oper(?=need)Match "oper" only if it is followed by "need".
oper(?!not)Match "oper" only if it is not followed by "not".
either|orMatch "either" or "or".
{int}Match exactly int occurences of the preceding item.
{int,}Match at least int occurences of the preceding item.
{int1,int2}Match at least int1 occurences of the preceding item but no more then int2.
[pqr]Match any one of the enclosed characters. Use a hyphen to specify a range of characters.
[^pqr]Match anything except the characters in brackets.
[\b]Match a backspace.
\bMatch a word boundary.
\BMatch a non-word boundary.
\cQMatch a control string, e.g. Control-Q
\dMatch a digit.
\DMatch any non-digit character.
\fMatch a form feed.
\nMatch a line feed.
\rMatch a carriage return.
\sMatch a single white space.
\SMatch a non-white space.
\tMatch a tab.
\vMatch a vertical tab.
\wMatch any alphanumeric character.
\WMatch any non-word character.
\intA reference back int matches.
\0Match a null character.
\xYYMatch the character code YY.
\xYYYYMatch the character code YYYY.


Properties

QualifiersPropertyTypeDescription
public get globalBooleanGlobal flag. If the global modifier was specified, the regular expression will search through the entire input string looking for matches.
public get ignoreCaseBooleanIgnore case flag. If the ignore case modifier was specifed, the regular expression is case insensitive.
public get setlastIndexNumberThe integer index of the end of the last match plus one. This is the index to start the next match for global patterns. This is only set if the "g" flag was used. It is set to the match ending index plus one. Set to zero if no match.
public get matchedStringSubstring last matched. Set to the matched string or null if there were no matches.
public get multilineBooleanMultiline flag. If the multiline modifier was specified, the regular expression will search through carriage return and new line characters in the input.
public get sourceStringRegular expression source pattern currently set.
public get startNumberInteger index of the start of the last match. This is only set if the "g" flag was used.
public get stickyBooleanSticky flag. If the sticky modifier was specified, the regular expression will only match from the lastIndex.

RegExp Methods

QualifiersMethod
public exec(str: String, start: Number = 0): Array
 Match this regular expression against the supplied string.
RegExp(pattern: String, flags: String = null)
 Create a regular expression object that can be used to process strings.
public replace(str: String, replacement: Object): String
 Replace all the matches.
public split(target: String): Array
 Split the target string into substrings around the matching sections.
public test(str: String): Boolean
 Test whether this regular expression will match against a string.
public override toString(): String
 Convert the regular expression to a string.

Method Detail

public exec(str: String, start: Number = 0): Array

Match this regular expression against the supplied string.

Description
By default, the matching starts at the beginning of the string.
Parameters
str: String String to match.
start: Number Optional starting index for matching. [default: 0]
Returns
Array of results, empty array if no matches.
Specified
ejs adds start argument.

public RegExp(pattern: String, flags: String = null)

Create a regular expression object that can be used to process strings.

Parameters
pattern: String The pattern to associated with this regular expression.
flags: String "g" for global match, "i" to ignore case, "m" match over multiple lines, "y" for sticky match. [default: null]

public replace(str: String, replacement: Object): String

Replace all the matches.

Description
This call replaces all matching substrings with the corresponding array element. If the array element is not a string, it is converted to a string before replacement.
Parameters
str: String String to match and replace.
replacement: Object Replacement text.
Returns
A string with zero, one or more substitutions in it.
Specified
ejscript-1.1

public split(target: String): Array

Split the target string into substrings around the matching sections.

Parameters
target: String String to split.
Returns
Array containing the matching substrings.
Specified
ejscript-1.1

public test(str: String): Boolean

Test whether this regular expression will match against a string.

Parameters
str: String String to search.
Returns
True if there is a match, false otherwise.
Specified
ejscript-1.1

override public toString(): String

Convert the regular expression to a string.

Returns
A string representation of the regular expression.