Regular expressions are used for searching or extracting wanted character(s) in a pattern and from a given expression. The syntax example is:
var expression = /pattern/modifiers;
The next segments include table showing which modifiers (flags) may be used with RegExp, followed by tables listing meta characters, brackets and quantifiers that together make RegExp pattern and finally tables listing RegExp properties and methods.
MODIFIER |
DESCRIPTION |
---|
g |
Indicates that the pattern will be applied to all of the examined string instead of just returning the result after the first match was found. |
i |
Indicates that the case-insensitive search mode should be applied. |
m |
Indicates that the multiline search mode will used and the pattern will continue looking after the end of line is reached (line of text). |
METACHARACTER |
DESCRIPTION |
---|
. |
Find a single character, except newline or line terminator. |
\w |
Find a word character (including digits and underscore). |
\W |
Find a non-word character. |
\d |
Find a digit. |
\D |
Find a non-digit character. |
\s |
Find a whitespace character. |
\S |
Find a non-whitespace character. |
\b |
Find a match at the beginning/end of a word. |
\B |
Find a match not at the beginning/end of a word. |
\0 |
Find a NULL character. |
\n |
Find a new line character. |
\f |
Find a form feed character. |
\r |
Find a carriage return character. |
\t |
Find a tab character. |
\v |
Find a vertical tab character. |
\xxx |
Find the character specified by an octal number xxx. |
\xdd |
Find the character specified by a hexadecimal number dd. |
\uxxxx |
Find the Unicode character specified by a hexadecimal number xxxx. |
EXPRESSION |
DESCRIPTION |
---|
[abc] |
Find any character between the brackets. |
[^abc] |
Find any character not between the brackets. |
[0-9] |
Find any digit from 0 to 9. |
[A-Z] |
Find any character from uppercase A to uppercase Z. |
[a-z] |
Find any character from lowercase a to lowercase z. |
[A-z] |
Find any character from uppercase A to lowercase z. |
(abcxyz) |
Find any character in the given set. |
(^abcxyz) |
Find any character outside the given set. |
(x|y|z) |
Find any of the alternatives specified but not all. |
QUANTIFIER |
DESCRIPTION |
---|
n+ |
Matches any string that contains at least one n. |
n* |
Matches any string that contains zero or more occurrences of n. |
.n? |
Matches any string that contains zero or one occurrences of n. |
n{X} |
Matches any string that contains a sequence of X n's. |
n{X,Y} |
Matches any string that contains a sequence of X to Y n's. |
n{X,} |
Matches any string that contains a sequence of at least X n's. |
n$ |
Matches any string with n at the end of it. |
^n |
Matches any string with n at the beginning of it. |
?=n |
Matches any string that is followed by a specific string n. |
?!n |
Matches any string that is not followed by a specific string n. |
PROPERTY |
TYPE |
ABBR. |
DESCRIPTION |
---|
global |
instance |
|
A Boolean value that indicates if the g modifier has been set. |
ignoreCase |
instance |
|
A Boolean value that indicates if the i modifier has been set. |
lastIndex |
instance |
|
An integer value that indicates the index (position) of a character at which the next match is going to start ("0" refers to the first character). |
multiline |
instance |
|
A Boolean value that indicates if the m modifier has been set. |
source |
instance |
|
A string value that contains the pattern (text) of the regular expression (in its literal form). |
input |
constructor |
$_ |
Shows the last string matched against. |
lastMatch |
constructor |
$& |
Shows the last matched text. |
lastParen |
constructor |
$+ |
Shows the last matched capturing group. |
leftContext |
constructor |
$‘ |
Shows the text that appears in the input string before the lastMatch. |
multiline |
constructor |
$* |
Indicates (as Boolean) if all expressions should use multiline mode. |
rightContext |
constructor |
$’ |
Shows the text that appears in the input string after the lastMatch. |
METHOD |
TYPE |
DESCRIPTION |
---|
exec() |
instance |
Extracts groups of matched data from an expression and stores them as arrays. If no matched data is found the return value will be NULL. |
test() |
instance |
Returns true if the pattern matches the argument or false if it doesn't. |
compile() |
instance |
Modifies (compiles) an existing regular expression during script execution. |
Comments
No comments have been made yet.
Please login to leave a comment. Login now