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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/((.*?)(\;))(.*?)/m'; $str = 'C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;C:\\ProgramData\\Anaconda3\\bin;C:\\ProgramData\\Anaconda3\\condabin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files\\CMake\\bin;C:\\MinGW\\bin;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.26.28801\\bin\\Hostx64\\x64;C:\\Users\\romeda\\AppData\\Roaming\\Python\\Python37\\Scripts;C:\\Program Files (x86)\\Common Files\\Intel\\Shared Libraries\\redist\\intel64_win\\compiler;C:\\Program Files\\Java\\jdk1.8.0_241\\bin;C:\\Oracle\\instantclient_19_6;C:\\Oracle\\product\\12.1.0\\client_2;C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Scripts;C:\\ProgramData\\Anaconda3\\pkgs\\conda-4.5.4-py36_0\\Scripts;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\Program Files (x86)\\Graphviz2.38\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\libnvvp;C:\\Program Files\\NVIDIA Corporation\\NVSMI;C:\\Program Files\\NVIDIA Corporation\\Nsight Compute 2019.4.0;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32\\config\\systemprofile\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files (x86)\\Adaptiva\\AdaptivaClient\\bin\\x32;C:\\Program Files (x86)\\Adaptiva\\AdaptivaClient\\bin\\x64;C:\\Program Files (x86)\\Webex\\Webex\\Applications;C:\\Program Files\\PuTTY;C:\\Program Files\\Git\\cmd;C:\\Program Files\\MongoDB\\Server\\4.2\\bin;C:\\Program Files\\FlexNet;C:\\ProgramData\\Anaconda3\\envs\\gis\\orca_app;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0;C:\\WINDOWS\\System32\\OpenSSH;C:\\Users\\romeda\\MiKTeX 2.9\\miktex\\bin\\x64;C:\\Users\\romeda\\batchfiles;C:\\Program Files\\Amazon\\AWSSAMCLI\\bin;C:\\Users\\romeda\\AppData\\Local\\Programs\\ArcGIS\\Pro\\bin;C:\\OSGeo4W64\\bin;C:\\OSGeo4W64\\bin\\gdalplugins;c:\\spark\\bin;C:\\Program Files (x86)\\Java\\jdk1.8.0_202\\bin;C:\\Users\\romeda\\MiKTeX\\miktex\\bin\\x64;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Amazon\\AWSCLIV2;C:\\Users\\romeda\\partiql-cli\\bin;C:\\Program Files (x86)\\FME;C:\\Program Files\\FME;C:\\MinGW\\bin;C:\\Users\\romeda\\MiKTeX\\miktex\\bin\\x64;C:\\Program Files (x86)\\Graphviz2.38\\bin;C:\\Users\\romeda\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\romeda\\AppData\\Local\\atom\\bin;C:\\Users\\romeda\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\romeda\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\JetBrains\\PyCharm 2020.1.1\\bin;.;C:\\Program Files (x86)\\GitHub CLI;.;C:\\Users\\romeda\\AppData\\Local\\Programs\\Microsoft VS Code\\bin'; $subst = "\1\n"; $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