Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gmixX

Test String

Code Generator

Generated Code

$re = '/ (?: (?<ctrl_code> # ^[[ # ^[ | \003 ([\^][\[]{2}) | # [Ctrl Key] >>> \'\e\' | \'^[\' | \'\u001B\' (?<esc> [\^][\[] | [\\\\][e] | [\\\\](?:(?i)u001b(?-i)) ) | # ^ ([\^][A-Z@])|([\^]) | # [Meta Key] \M- ([\\\\]M-) | # [^C] ^C | \003 ([\^]C|[\\\\]0{2}3) ) )+/mixX'; $str = '# Ctrl bindkey \'\\e\' zle_function bindkey \'\\E\' zle_function bindkey \'^[\' zle_function bindkey \'\\U001b\' zle_function bindkey \'\\U001B\' zle_function bindkey \'\\u001b\' zle_function bindkey \'\\u001B\' zle_function # Function keys ^[OS ^[[34~ ^[[24;6~ ^[[21;2~ ^[[18~ ^[[14^ ^[OR ^[[34^ ^[[24;5~ ^[[21~ ^[[18^ ^[[13;6~ ^[OQ ^[[33~ ^[[24;2~ ^[[21^ ^[[17;6~ ^[[13;5~ ^[OP ^[[33^ ^[[24$ ^[[20;6~ ^[[17;5~ ^[[13;2~ ^[O6S ^[[32~ ^[[24~ ^[[20;5~ ^[[17;2~ ^[[13~ ^[O6R ^[[32^ ^[[24^ ^[[20;2~ ^[[17~ ^[[13^ ^[O6Q ^[[31~ ^[[24@ ^[[20~ ^[[17^ ^[[12;6~ ^[O6P ^[[31^ ^[[23;6~ ^[[20^ ^[[15;6~ ^[[12;5~ ^[O5S ^[[29~ ^[[23;5~ ^[[19;6~ ^[[15;5~ ^[[12;2~ ^[O5R ^[[29^ ^[[23;2~ ^[[19;5~ ^[[15;2~ ^[[12~ ^[O5Q ^[[28~ ^[[23$ ^[[19;2~ ^[[15~ ^[[12^ ^[O5P ^[[28^ ^[[23~ ^[[19~ ^[[15^ ^[[11;6~ ^[O2S ^[[26~ ^[[23^ ^[[19^ ^[[14;6~ ^[[11;5~ ^[O2R ^[[26^ ^[[23@ ^[[18;6~ ^[[14;5~ ^[[11;2~ ^[O2Q ^[[25~ ^[[21;6~ ^[[18;5~ ^[[14;2~ ^[[11~ ^[O2P ^[[25^ ^[[21;5~ ^[[18;2~ ^[[14~ ^[[11^ # bindkey -L | clip bindkey "^[\\$" spell-word bindkey "^[0" digit-argument bindkey "^[[1;10A" beginning-of-buffer-or-history bindkey \'^[[1;10A\' beginning-of-buffer-or-history bindkey "^[[1;10B" end-of-buffer-or-history bindkey \'^[[1;10B\' end-of-buffer-or-history bindkey "^[[1;3C" forward-word bindkey \'^[[1;3C\' forward-word bindkey "^[[1;3D" backward-word bindkey \'^[[1;3D\' backward-word bindkey "^[[1;5C" forward-word bindkey "^[[1;5D" backward-word bindkey "^[[1;6C" end-of-line bindkey \'^[[1;6C\' end-of-line bindkey "^[[1;6D" beginning-of-line bindkey \'^[[1;6D\' beginning-of-line bindkey "^[[1;9C" forward-word bindkey \'^[[1;9C\' forward-word bindkey "^[[1;9D" backward-word bindkey \'^[[1;9D\' backward-word bindkey "^[1" digit-argument bindkey "^[[200~" bracketed-paste bindkey "^[2" digit-argument bindkey "^[[3~" delete-char bindkey "^[3" digit-argument bindkey "^[4" digit-argument bindkey "^[5" digit-argument bindkey "^[[5~" up-line-or-history bindkey "^[6" digit-argument bindkey "^[[6~" down-line-or-history bindkey "^[7" digit-argument bindkey "^[8" digit-argument bindkey "^[9" digit-argument bindkey "^[a" accept-and-hold bindkey "^[A" accept-and-hold bindkey "^A" beginning-of-line bindkey "^[[A" history-beginning-search-backward bindkey "^?" backward-delete-char bindkey "^[^?" backward-kill-word bindkey "^[~" _bash_complete-word bindkey "^[b" backward-word bindkey "^[B" backward-word bindkey "^[[B" down-line-or-history bindkey "^[<" beginning-of-buffer-or-history bindkey "^B" zhistory bindkey "^[c" capitalize-word bindkey "^[[C" forward-char bindkey "^[}" _complete_debug bindkey "^[]" _complete_help bindkey "^[^]" _complete_tag bindkey "^[^_" copy-prev-word bindkey "^[^[" cycle-completion-positions bindkey "^[C" zle-debug-view bindkey "^[[D" backward-char bindkey "^D" delete-char-or-list bindkey "^[/" describe-key-briefly bindkey \'^[/\' describe-key-briefly bindkey "^[[" describe-key-more bindkey "^[d" kill-word bindkey "^[D" kill-word bindkey "^[^D" list-choices bindkey "^[{" dump-zstyle-context bindkey "^[^E" edit-command-line bindkey \'^[^E\' edit-command-line bindkey "^E" end-of-line bindkey "^[>" end-of-buffer-or-history bindkey "^[E" open-buffer-in-editor bindkey "^[ " expand-global-alias bindkey "^[!" expand-history bindkey "^F" forward-char bindkey "^[f" forward-word bindkey "^[F" forward-word bindkey "^[g" get-line bindkey \'^[g\' get-line bindkey "^[G" push-input bindkey \'^[G\' push-input bindkey "^[^G" send-break bindkey "^G" send-break bindkey "^H" backward-delete-char bindkey "^[^H" backward-kill-word bindkey "^[," _history-complete-newer bindkey "^[h" zew-history-complete-word bindkey "^[H" zew-history-complete-word-backwards bindkey "^I" expand-or-complete bindkey "^[." insert-last-word bindkey "^[_" insert-last-word bindkey "^[^I" self-insert-unmeta bindkey "^[^J" self-insert-unmeta bindkey "^J" self-insert-unmeta bindkey "^K" kill-line bindkey "^[^L" clear-screen bindkey "^L" clear-screen bindkey "^[L" down-case-word bindkey "^M" accept-line bindkey " " magic-space bindkey "^[man" man-command-line bindkey "\\M-B\\M-^V" pasteWSL bindkey "\\M-B\\M-^V" pasteWSL bindkey "\\M-B" self-insert bindkey "^[m" copy-earlier-word bindkey "^[M" copy-prev-shell-word bindkey "^[^M" self-insert-unmeta bindkey "^N" down-line-or-history bindkey "^[-" neg-argument bindkey "^[n" history-search-forward bindkey "^[N" history-search-forward bindkey "^O" accept-line-and-down-history bindkey "^[OA" up-line-or-beginning-search bindkey "^[OB" down-line-or-beginning-search bindkey "^[OC" forward-char bindkey "^[OD" backward-char bindkey "^[OF" end-of-line bindkey "^[OH" beginning-of-line bindkey "^O^Z" zui-demo-various bindkey "^[p" history-search-backward bindkey "^[P" history-search-backward bindkey "^P" up-line-or-history bindkey "^[q" push-line bindkey "^[Q" push-line bindkey "^Q" push-line bindkey "^[\'" quote-line bindkey "^[\\"" quote-region bindkey -R "\\M-C"-"\\M-^?" self-insert bindkey -R "\\M-^@"-"\\M-A" self-insert bindkey -R "!"-"~" self-insert bindkey "^[r" zew-rotate-shell-words bindkey "^[R" zew-rotate-shell-words-backwards bindkey "^R" znt-history-widget bindkey "^@" set-mark-command bindkey "^S" history-incremental-search-forward bindkey -s "^[l" "ls^J" bindkey "^[s" spell-word bindkey "^[S" spell-word bindkey "^[T" insert-indented-line bindkey "^T" zca-widget bindkey "^[t" zew-transpose-shell-words bindkey "^U" kill-whole-line bindkey "^_" undo bindkey "^[u" up-case-word bindkey "^[U" up-case-word bindkey "^[|" vi-goto-column bindkey "^V" quoted-insert bindkey "^W" backward-kill-word bindkey "^[W" copy-region-as-kill bindkey "^[?" which-command bindkey "^[w" zew-backward-kill-shell-word bindkey "^Xa" _expand_alias bindkey "^X~" _bash_list-choices bindkey "^X^B" vi-match-bracket bindkey "^XC" _correct_filename bindkey "^Xc" _correct_word bindkey "^X?" _complete_debug bindkey "^Xd" _list_expansions bindkey "^X^E" edit-command-line bindkey "^Xe" _expand_word bindkey "^[x" execute-named-cmd bindkey "^X*" expand-word bindkey "^X^F" vi-find-next-char bindkey "^Xg" list-expand bindkey "^XG" list-expand bindkey "^Xh" _complete_help bindkey "^X^J" vi-join bindkey "^X^K" kill-buffer bindkey "^Xm" _most_recent_file bindkey "^X^N" infer-next-history bindkey "^Xn" _next_tags bindkey "^X^O" overwrite-mode bindkey "^Xr" history-incremental-search-backward bindkey "^X^R" _read_comp bindkey "^Xs" history-incremental-search-forward bindkey "^Xt" _complete_tag bindkey "^Xu" undo bindkey "^X^U" undo bindkey "^X^V" vi-cmd-mode bindkey "^X=" what-cursor-position bindkey "^X^X" exchange-point-and-mark bindkey "^[y" transpose-words-match bindkey "^Y" yank bindkey "^[z" execute-last-named-cmd bindkey "^[^Z" redo bindkey \'^[^Z\' redo bindkey "^[[Z" reverse-menu-complete bindkey "^Z" undo bindkey \'^Z\' undo '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php