Regular Expression (regex aka RE) Demo

Please enter your pattern (as a regular expression) and data; this program will show below if the data matches the pattern. You can select a common pattern to get started.

Common pattern:

Pattern:

Data:



You need to enable Javascript for this to work.



Some key parts of the regex language:

  1. Letters and digits stand for themselves, a “.” matches any one character (except newline or carriage return), “[...]” lists a set of acceptable characters (these are all atoms).
  2. An atom may be followed by a duplication marker, creating a piece: “*” means match 0 or more of the previous atom, “+” means match 1 or more of the previous atom, “?” means the previous atom is optional, “{n,m}” means n through m of the previous atom.
  3. “(...)” groups a sequence of pieces into one atom.
  4. “|” separates alternative sequences of pieces.

When using regular expressions as a filter, be sure that it begins with ^ (match data beginning) and ends with $ (match data ending). Beware: the | has lower precedence.

Regexper.com provides a delightful visualization of regular expressions.

You can get a similar text-based C program regex.c if you want to try out POSIX EREs instead of Javascript regular expressions (they have much in common but are not identical).

(C) Copyright 2012 David A. Wheeler.