## Regex Tester

Enter your regular expression in the text box below, then enter text you'd like to test the regular expression on in the second text box. The results will be highlighted below.

#### Result

##### Regex Help

Regex, also known as regular expressions, is a way of defining a text search pattern. It is usually used for finding or replacing text in a string.

The following tables show you the most commonly used characters and their uses.

Character Class ASCII Description
\w [A-Za-z0-9_] Alphanumeric characters and "_"
\W [^A-Za-z0-9_] Non-word characters
\a [A-Za-z] Alphabetic characters (upper and lowercase)
\s [ \t] Space and tab
\b (?<=\W)(?=\w)|(?<=\w)(?=\W) Word boundaries
\d [0-9] Numerical Digits
\D [^0-9] Non-numerical digits
\l [a-z] Lowercase letters
\p [\x20-\x7E] Any visible character or the space character
\s [ \t\r\n\v\f] Any whitespace characters
\S [^ \t\r\n\v\f] Any non-whitespace characters
\u [A-Z] Uppercase letters
\x [A-Fa-f0-9] Hexadecimal digits
Metacharacter Description
* Matches the preceding element zero or more times. For example, ab*c matches "ac", "abc", "abbbc", etc. [xyz]* matches "", "x", "y", "z", "zx", "zyx", "xyzzy", and so on. (ab)* matches "", "ab", "abab", "ababab", and so on.
+ Matches the preceding element one or more times. For example, ab+c matches "abc", "abbc", "abbbc", and so on, but not "ac".
? Matches the preceding element zero or one time. For example, ab?c matches only "ac" or "abc".
| The choice (also known as alternation or set union) operator matches either the expression before or the expression after this operator. For example, abc|def can match either "abc" or "def".
. Matches any single character (many applications exclude newlines, and exactly which characters are considered newlines is flavor-, character-encoding-, and platform-specific, but it is safe to assume that the line feed character is included). Within POSIX bracket expressions, the dot character matches a literal dot. For example, a.c matches "abc", etc., but [a.c] matches only "a", ".", or "c".
^ Matches the starting position in the string, like the startsWith() function. In line-based tools, it matches the starting position of any line.
? Matches the ending position of the string or the position just before a string-ending newline, like the endsWith() function. In line-based tools, it matches the ending position of any line.

Credit to Wikipedia for some of the regex descriptions.

##### JavaScript

Using regex in JS is really easy since it is built right in to the language. Here is a quick example:

"12 34".match( /\d+/g )    // ['12', '34']


Regex strings in JavaScript are a bit different than normal strings. They're delimited with the forward slash (/) character instead of quotes.

At the end of the regex string I showed above you might have noticed the extra g (global). This is a flag indicating that we want to find all matches in the string, and not just the first one. There are a few other flags available, like ignore case (i), multi-line (m), and sticky (y), which is still in experimental mode.