RegExp
Module | ejs |
Definition | final class RegExp |
Inheritance | RegExp ![]() |
Specified | evolving |
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|or | Match "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. |
\b | Match a word boundary. |
\B | Match a non-word boundary. |
\cQ | Match a control string, e.g. Control-Q |
\d | Match a digit. |
\D | Match any non-digit character. |
\f | Match a form feed. |
\n | Match a line feed. |
\r | Match a carriage return. |
\s | Match a single white space. |
\S | Match a non-white space. |
\t | Match a tab. |
\v | Match a vertical tab. |
\w | Match any alphanumeric character. |
\W | Match any non-word character. |
\int | A reference back int matches. |
\0 | Match a null character. |
\xYY | Match the character code YY. |
\xYYYY | Match the character code YYYY. |
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
public get | global | Boolean | Global flag. If the global modifier was specified, the regular expression will search through the entire input string looking for matches. |
public get | ignoreCase | Boolean | Ignore case flag. If the ignore case modifier was specifed, the regular expression is case insensitive. |
public get set | lastIndex | Number | The 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 | matched | String | Substring last matched. Set to the matched string or null if there were no matches. |
public get | multiline | Boolean | Multiline flag. If the multiline modifier was specified, the regular expression will search through carriage return and new line characters in the input. |
public get | source | String | Regular expression source pattern currently set. |
public get | start | Number | Integer index of the start of the last match. This is only set if the "g" flag was used. |
public get | sticky | Boolean | Sticky flag. If the sticky modifier was specified, the regular expression will only match from the lastIndex. |
RegExp Methods
Qualifiers | Method |
---|---|
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
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.
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.
- Returns
- A string with zero, one or more substitutions in it.
- Specified
- ejscript-1.1
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
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.