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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/(\w+)\s\w(\d+)((\s)\w(\d+)\])*$/m'; $str = '# Circuit generated by QLib # Bernstein-Vazirani search # Secret= 1 .qubit 11 qubit x0 qubit x1 qubit x2 qubit x3 qubit x4 qubit x5 qubit x6 qubit x7 qubit x8 qubit x9 qubit y Prep0 y .begin X y H x0 H x1 H x2 H x3 H x4 H x5 H x6 H x7 H x8 H x9 H y CNOT x0 y H x0 H x1 H x2 H x3 H x4 H x5 H x6 H x7 H x8 H x9 H y .end # Circuit generated by QLib # QFT for 15 qubits .qubit 15 qubit q0 qubit q1 qubit q2 qubit q3 qubit q4 qubit q5 qubit q6 qubit q7 qubit q8 qubit q9 qubit q10 qubit q11 qubit q12 qubit q13 qubit q14 .begin H q0 CP q1 q0 2 CP q2 q0 1 CP q3 q0 0.5 CP q4 q0 0.25 CP q5 q0 0.125 CP q6 q0 0.0625 CP q7 q0 0.03125 CP q8 q0 0.015625 CP q9 q0 0.0078125 CP q10 q0 0.00390625 CP q11 q0 0.00195312 CP q12 q0 0.000976562 CP q13 q0 0.000488281 CP q14 q0 0.000244141 H q1 CP q2 q1 2 CP q3 q1 1 CP q4 q1 0.5 CP q5 q1 0.25 CP q6 q1 0.125 CP q7 q1 0.0625 CP q8 q1 0.03125 CP q9 q1 0.015625 CP q10 q1 0.0078125 CP q11 q1 0.00390625 CP q12 q1 0.00195312 CP q13 q1 0.000976562 CP q14 q1 0.000488281 H q2 CP q3 q2 2 CP q4 q2 1 CP q5 q2 0.5 CP q6 q2 0.25 CP q7 q2 0.125 CP q8 q2 0.0625 CP q9 q2 0.03125 CP q10 q2 0.015625 CP q11 q2 0.0078125 CP q12 q2 0.00390625 CP q13 q2 0.00195312 CP q14 q2 0.000976562 H q3 CP q4 q3 2 CP q5 q3 1 CP q6 q3 0.5 CP q7 q3 0.25 CP q8 q3 0.125 CP q9 q3 0.0625 CP q10 q3 0.03125 CP q11 q3 0.015625 CP q12 q3 0.0078125 CP q13 q3 0.00390625 CP q14 q3 0.00195312 H q4 CP q5 q4 2 CP q6 q4 1 CP q7 q4 0.5 CP q8 q4 0.25 CP q9 q4 0.125 CP q10 q4 0.0625 CP q11 q4 0.03125 CP q12 q4 0.015625 CP q13 q4 0.0078125 CP q14 q4 0.00390625 H q5 CP q6 q5 2 CP q7 q5 1 CP q8 q5 0.5 CP q9 q5 0.25 CP q10 q5 0.125 CP q11 q5 0.0625 CP q12 q5 0.03125 CP q13 q5 0.015625 CP q14 q5 0.0078125 H q6 CP q7 q6 2 CP q8 q6 1 CP q9 q6 0.5 CP q10 q6 0.25 CP q11 q6 0.125 CP q12 q6 0.0625 CP q13 q6 0.03125 CP q14 q6 0.015625 H q7 CP q8 q7 2 CP q9 q7 1 CP q10 q7 0.5 CP q11 q7 0.25 CP q12 q7 0.125 CP q13 q7 0.0625 CP q14 q7 0.03125 H q8 CP q9 q8 2 CP q10 q8 1 CP q11 q8 0.5 CP q12 q8 0.25 CP q13 q8 0.125 CP q14 q8 0.0625 H q9 CP q10 q9 2 CP q11 q9 1 CP q12 q9 0.5 CP q13 q9 0.25 CP q14 q9 0.125 H q10 CP q11 q10 2 CP q12 q10 1 CP q13 q10 0.5 CP q14 q10 0.25 H q11 CP q12 q11 2 CP q13 q11 1 CP q14 q11 0.5 H q12 CP q13 q12 2 CP q14 q12 1 H q13 CP q14 q13 2 H q14 .end '; $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