Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/\d{2}:\d{2}:\d{2} \d*/'; $str = '23:58:02 106 23:58:07 105 23:58:12 103 23:58:17 98 23:58:22 100 23:58:27 97 23:58:32 99 23:58:37 100 23:58:42 99 23:58:47 104 23:58:52 95 23:58:57 96 23:59:02 98 23:59:07 96 23:59:12 104 23:59:17 109 23:59:22 105 23:59:27 111 23:59:32 111 23:59:37 104 23:59:42 110 23:59:47 100 23:59:52 106 23:59:57 114 00:00:02 123 00:00:07 130 00:00:12 130 00:00:17 125 00:00:22 119 00:00:27 116 00:00:32 122 00:00:37 116 00:00:42 119 00:00:47 117 00:00:52 114 00:00:57 114 00:01:02 110 00:01:07 103 00:01:12 98 00:01:17 98 00:01:22 102 00:01:27 97 00:01:32 99 00:01:37 93 00:01:42 97 00:01:47 103 00:01:52 96 00:01:57 93 00:02:02 93 00:02:07 95 00:02:12 106 00:02:17 99 00:02:22 102 00:02:27 96 00:02:32 93 00:02:37 97 00:02:42 102 00:02:47 101 00:02:52 95 00:02:57 92 00:03:02 100 00:03:07 95 00:03:12 102 00:03:17 102 00:03:22 109 00:03:27 109 00:03:32 107 00:03:37 111 00:03:42 112 00:03:47 113 00:03:52 115 '; $subst = ""; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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