RegExp
Module | ejs |
Namespace | intrinsic |
Definition | final class RegExp |
Inheritance | RegExp ![]() |
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 |
---|---|---|---|
No properties defined |
RegExp Methods
Qualifiers | Method |
---|---|
public | exec(str: String, start: Number): Array |
Match this regular expression against a string. | |
public get | global(): Boolean |
Get the global flag this regular expression is using. | |
public get | ignoreCase(): Boolean |
Get the case flag this regular expression is using. | |
public get | lastIndex(): Number |
Get the integer index of the end of the last match plus one. | |
public set | lastIndex(value: Number): Void |
Set the integer index of the end of the last match plus one. | |
public get | matched(): String |
Get the substring that was last matched. | |
public get | multiline(): Boolean |
Get the multiline flag this regular expression is using. | |
RegExp(pattern: String, flags: String) | |
Create a regular expression object that can be used to process strings. | |
public | replace(str: String, replacement: Object): String |
Replace all the matches. | |
public get | source(): String |
Get the regular expression source pattern is using to match with. | |
public | split(target: String): Array |
Split the target string into substrings around the matching sections. | |
public get | start(): Number |
Get the integer index of the start of the last match. | |
public get | sticky(): Boolean |
Get the sticky flag this regular expression is using. | |
public | test(str: String): Boolean |
Test whether this regular expression will match against a string. | |
public override | toString(locale: String): String |
Convert the regular expression to a string. |
Method Detail
Match this regular expression against a string.
- Description
- By default, the matching starts at the beginning of the string.
- Returns
- Array of results, empty array if no matches.
- Specified
- Ejs-11 adds start argument.
Get the global flag this regular expression is using.
- Description
- If the global flag is set, the regular expression will search through the entire input string looking for matches.
- Returns
- The global flag, true if set, false otherwise.
- Specified
- Ejs-11.
Get the case flag this regular expression is using.
- Description
- If the ignore case flag is set, the regular expression is case insensitive.
- Returns
- The case flag, true if set, false otherwise.
- Specified
- Ejs-11.
Get the integer index of the end of the last match plus one.
- Description
- This is the index to start the next match for global patterns.
- Returns
- Match end plus one or -1 if there is no last match.
Set the integer index of the end of the last match plus one.
- Description
- This is the index to start the next match for global patterns.
- Returns
- Match end plus one or -1 if there is no last match.
Get the substring that was last matched.
- Returns
- The matched string or null if there were no matches.
- Specified
- Ejs-11.
Get the multiline flag this regular expression is using.
- Description
- If the multiline flag is set, the regular expression will search through carriage return and new line characters in the input.
- Returns
- The multiline flag, true if set, false otherwise.
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.
- Returns
- A string with zero, one or more substitutions in it.
- Specified
- Ejs-11.
Get the regular expression source pattern is using to match with.
- Returns
- The pattern string.
Split the target string into substrings around the matching sections.
- Parameters
- Returns
- Array containing the matching substrings.
- Specified
- Ejs-11.
Get the integer index of the start of the last match.
- Returns
- Match start.
- Specified
- Ejs-11.
Get the sticky flag this regular expression is using.
- Description
- If the sticky flag is set, the regular expression contained the character flag "y".
- Returns
- The sticky flag, true if set, false otherwise.
- Specified
- Ejs-11.
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-11.
Convert the regular expression to a string.
- Parameters
locale: String Locale
- Returns
- A string representation of the regular expression.