JAVASCRIPT TUTORIALS - Javascript - RegExp
Javascript - RegExp
ADVERTISEMENTS
|
ADVERTISEMENTS
Brackets:
Expression | Description |
---|---|
[...] | Any one character between the brackets. |
[^...] | Any one character not between the brackets. |
[0-9] | It matches any decimal digit from 0 through 9. |
[a-z] | It matches any character from lowercase a through lowercase z. |
[A-Z] | It matches any character from uppercase A through uppercase Z. |
[a-Z] | It matches any character from lowercase a through uppercase Z. |
ADVERTISEMENTS
Expression | Description |
---|---|
p+ | It matches any string containing at least one p. |
p* | It matches any string containing zero or more p's. |
p? | It matches any string containing one or more p's. |
p{N} | It matches any string containing a sequence of N p's |
p{2,3} | It matches any string containing a sequence of two or three p's. |
p{2, } | It matches any string containing a sequence of at least two p's. |
p$ | It matches any string with p at the end of it. |
^p | It matches any string with p at the beginning of it. |
Expression | Description |
---|---|
[^a-zA-Z] | It matches any string not containing any of the characters ranging from a through z and A through Z. |
p.p | It matches any string containing p, followed by any character, in turn followed by another p. |
^.{2}$ | It matches any string containing exactly two characters. |
<b>(.*)</b> | It matches any string enclosed within <b> and </b>. |
p(hp)* | It matches any string containing a p followed by zero or more instances of the sequence hp. |
Character | Description |
---|---|
Alphanumeric | Itself |
\0 | The NUL character (\u0000) |
\t | Tab (\u0009) |
\n | Newline (\u000A) |
\v | Vertical tab (\u000B) |
\f | Form feed (\u000C) |
\r | Carriage return (\u000D) |
\xnn | The Latin character specified by the hexadecimal number nn; for example, \x0A is the same as \n |
\uxxxx | The Unicode character specified by the hexadecimal number xxxx; for example, \u0009 is the same as \t |
\cX | The control character ^X; for example, \cJ is equivalent to the newline character \n |
|
Modifier | Description |
---|---|
i | Perform case-insensitive matching. |
m | Specifies that if the string has newline or carriage return characters, the ^ and $ operators will now match against a newline boundary, instead of a string boundary |
g | Perform a global matchthat is, find all matches rather than stopping after the first match. |
Property | Description |
---|---|
constructor | Specifies the function that creates an object's prototype. |
global | Specifies if the "g" modifier is set. |
ignoreCase | Specifies if the "i" modifier is set. |
lastIndex | The index at which to start the next match. |
multiline | Specifies if the "m" modifier is set. |
source | The text of the pattern. |
Method | Description |
---|---|
exec() | Executes a search for a match in its string parameter. |
test() | Tests for a match in its string parameter. |
toSource() | Returns an object literal representing the specified object; you can use this value to create a new object. |
toString() | Returns a string representing the specified object. |