Tools

Regular Expression Tester

This web page validates regular expression patterns against test input. You can even validate a pattern against multiple input lines simoultaneously, if you check off global match and multiline. I find this useful for URI rewrite testing, when you wish to match multiple URI's with a single pattern.
The implementation is based on JavaScript's RegExp, but you can also switch to the PHP regex engine for expressions which can't be evaluated in JavaScript1.





Engine:
   

Switches:
     

   

Sample patterns
^\w+([-+.']\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,6}$ E-mail address, e.g. "[email protected]" Test
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ IPv4 address, e.g. "123.123.123.123" Test
^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$ Host name, e.g. "ole.michelsen.dk" Test
^(.*/)?(?:$|(.+?)(?:(\.[^.]*$)|$)) Path, e.g. "/path/to/file.ext" Test

Special Characters
\Escape Character
\nNew line
\rCarriage return
\tTab
\vVertical tab
\fForm feed

Meta Characters (must be escaped)
^[.${
*()+\
|?<>

Character Classes
\wWord (a-z, A-Z, 0-9, including _ (underscore))
\WNon-word
\dDigit (0-9)
\DNon-digit
\sWhitespace
\SNot whitespace
\bMatch at beginning or end
\BDo not match at beginning or end
\0NUL character
\nNew line
Quantifiers
n*0 or more n
n*?0 or more n, ungreedy
n+1 or more n
n+?1 or more n, ungreedy
n?0 or 1 n
n??0 or 1 n, ungreedy
n{2}Exactly 2 n
n{2,}2 or more n
n{2,4}2, 3 or 4 n
n{2,4}?2, 3 or 4 n, ungreedy

Anchors
^Start of line
$End of line

Assertions
n(?=o)Lookahead, n followed by o
(not matching o)
n(?!o)Negative lookahead, n not followed by o
(not matching o)
(?<=o)nLookbehind1, o preceding n
(?<!o)nNegative lookbehind1, o not preceding n
Ranges
.Any character except new line (\n)
(a|b)a or b
(...)Group
(?:...)Passive Group
[abc]Range (a, b or c)
[^abc]Not a, b or c
[a-z]Character between a and z, lower case
[A-Z]Character between A and Z, upper case
[0-9]Number between 0 and 9
[a-zA-Z0-9]Characters between a and z (both cases), and numbers between 0 and 9
\nnth group/subpattern
  1. The JavaScript RegExp object does not support lookbehind assertions. Instead I've created a fall-back to the PHP regex engine, which will automatically be used instead, if a lookbehind is detected.