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 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
get globalBooleanGlobal flag. If the global modifier was specified, the regular expression will search through the entire input string looking for matches.
get ignoreCaseBooleanIgnore case flag. If the ignore case modifier was specified, the regular expression is case insensitive.
get set lastIndexNumberThe 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.
get matchedStringSubstring last matched. Set to the matched string or null if there were no matches.
get multilineBooleanMultiline flag. If the multiline modifier was specified, the regular expression will search through carriage return and new line characters in the input.
get sourceStringRegular expression source pattern currently set.
get startNumberGet the integer index of the start of the last match. This is only set of the "g" global flax is used.
get stickyBooleanSticky flag. If the sticky modifier was specified, the regular expression will only match from the lastIndex.

RegExp Class Methods

(No own class methods defined)

QualifiersMethod

RegExp Instance Methods

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

Method Detail

RegExp(pattern: String, flags: String = null)
Description
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. "s" so that "." will match all characters. [default: null]

exec(str: String, start: Number = 0): Array
Description
Match this regular expression against the supplied string. 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. The first element is the entire match. Subsequent elements correspond to the matching sub-expressions. Returns null if not match.
Specified
ejs Adds start argument.

replace(str: String, replacement: Object): String
Description
Replace all the matches. 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. This can contain & to insert the matched substring, ` to insert the portion preceeding that matched substring, ' to insert the portion following the matched substring, n where n is the nth parentesized substring or $ to insert a literal character.
Returns
A string with zero, one or more substitutions in it.
Specified
ejs H

split(target: String): Array
Description
Split the target string into substrings around the matching sections.
Parameters
target: String String to split.
Returns
Array containing the matching substrings.
Specified
ejscript-2.5

test(str: String): Boolean
Description
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
ejs 8

override toString(): String
Description
Convert the regular expression to a string. This form will wrap the expression with slash delimiters and append the regular expression flags. For example: "/pattern/g".
Returns
A string representation of the regular expression. 8.