Javascript Regexp Tester and Cheat Sheet

This is a javascript regexp testing suite. A regexp cheat sheet is provided for easy reference, as are some sample patterns. Enjoy!


Character Classes
\c Control character
\s White space
\S Not white space
\d Digit
\D Not digit
\w Word
\W Not word
\x Hexadecimal digit
\O Octal digit
Special characters
^ [ . $ { * (
\ / + | ? < >
Must be escaped
\n New line
\r Carriage return
\t Tab
\v Vertical tab
\f Form feed
\xxx Octal character xxx
\xhh Hex character hh
POSIX
[:upper:] Upper case letters
[:lower:] Lower case letters
[:alpha:] All letters
[:alnum:] Digits and letters
[:digit:] Digits
[:xdigit:] Hexadecimal digits
[:punct:] Punctuation
[:blank:] Space and tab
[:cntrl:] Control character
[:graph:] Printed characters
[:print:] Printed characters and spaces
[:word:] Digits, letters and underscore
Quantifiers
* 0 or more
+ 1 or more
? 0 or 1
{3} Exactly 3
{3,} 3 or more
{3,5} 3,4 or 5
Groups and Ranges
. Any character except new line (\n)
(ab|ba) ab or ba
(...) Group
(?:...) Passive group
[abc] Range (a or b or c)
[^abc] Not a or b or c
[a-q] Letter from a to q
[A-Q] Upper case letter from A to Q
[0-7] Digit from 0 to 7
\n nth group/subpattern
Anchors
^ Start of string
\A Start of string
$ End of string
\Z End of string
\b Word boundary
\B Not word boundary
\< Start of word
\> End of word
Pattern Modifiers
g Global match
i Case-insensitive
m Multiple lines
s Treat string as single line
x Allow comments and white space in pattern
e Evaluate replacement
U Ungreedy pattern
Assertions
?= Lookahead assertion
?! Negative lookahead
?<= Lookbehind assertion
?!= or ?<! Negative lookbehind
?> Once-only Subexpression
?() Condition [if then]
?()| Condition [if then else]
?# Comment
String Replacement
(backreferences)
$n nth non-passive group
$2 "xyz" in /^(abc(xyz))$/
$1 "xyz" in /^(?:abc)(xyz)$/
$` Before matched string
$' After matched string
$+ Last matched string
$& Entire matched string

Enter your regular expression:




Test case 1:     
Test case 2:     
Test case 3:     
Test case 4:     
Test case 5:     

Right click this link to save this file

Contact:
Wey Wang
email: wey.wang [at] gmail [dot] com

Other scripts:
Youtube HD Embed Generator

Ninja vs Penguin
Forward Design

© 2008 NinjaVsPenguin.com