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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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
No Match

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression. sed -E 's/(\[.*\])(=>?)\s+(\w+[\(\)\d+\.]+)\s+?(\".*\"|\{[\s\w]+\})?/<i>$1<\/i><i>$2<\/i><i>$3<\/i><i>$4<\/i>/g;t' <<< "array(40) { [\"HTTP_AUTHORIZATION\"]=> string(0) \"\" [\"HTTP_HOST\"]=> string(12) \"galtrade.loc\" [\"HTTP_CONNECTION\"]=> string(10) \"keep-alive\" [\"HTTP_PRAGMA\"]=> string(8) \"no-cache\" [\"HTTP_CACHE_CONTROL\"]=> string(8) \"no-cache\" [\"HTTP_UPGRADE_INSECURE_REQUESTS\"]=> string(1) \"1\" [\"HTTP_USER_AGENT\"]=> string(142) \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 YaBrowser/19.3.0.2485 Yowser/2.5 Safari/537.36\" [\"HTTP_ACCEPT\"]=> string(85) \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\" [\"HTTP_ACCEPT_ENCODING\"]=> string(13) \"gzip, deflate\" [\"HTTP_ACCEPT_LANGUAGE\"]=> string(11) \"ru,en;q=0.9\" [\"HTTP_COOKIE\"]=> string(59) \"fdafa396c9597e51e294ef0cc64573a0=c0ntndm6dh8bg3vk901nrs1a05\" [\"PATH\"]=> string(502) \"c:\ospanel\modules\php\PHP-5.6\ext;c:\ospanel\modules\php\PHP-5.6\pear;c:\ospanel\modules\php\PHP-5.6\pear\bin;c:\ospanel\modules\php\PHP-5.6;c:\ospanel\modules\imagemagick;c:\ospanel\modules\wget\bin;c:\ospanel\modules\git;c:\ospanel\modules\git\bin;c:\ospanel\modules\git\mingw\bin;c:\ospanel\modules\git\cmd;c:\ospanel\modules\database\MySQL-5.6\bin;c:\ospanel\modules\http\Apache-2.4\bin;c:\ospanel\modules\http\Apache-2.4;C:\Windows\system32;C:\Windows;C:\Windows\system32\Wbem;C:\Windows\SysWOW64\" [\"SystemRoot\"]=> string(10) \"C:\Windows\" [\"COMSPEC\"]=> string(27) \"C:\Windows\system32\cmd.exe\" [\"PATHEXT\"]=> string(53) \".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC\" [\"WINDIR\"]=> string(10) \"C:\Windows\" [\"SERVER_SIGNATURE\"]=> string(0) \"\" [\"SERVER_SOFTWARE\"]=> string(6) \"Apache\" [\"SERVER_NAME\"]= string(12) \"galtrade.loc\" [\"SERVER_ADDR\"]=> string(9) \"127.0.0.1\" [\"SERVER_PORT\"]=> string(2) \"80\" [\"REMOTE_ADDR\"]=> string(9) \"127.0.0.1\" [\"DOCUMENT_ROOT\"]=> string(23) \"H:/Domains/galtrade.loc\" [\"REQUEST_SCHEME\"]=> string(4) \"http\" [\"CONTEXT_PREFIX\"]=> string(0) \"\" [\"CONTEXT_DOCUMENT_ROOT\"]=> string(23) \"H:/Domains/galtrade.loc\" [\"SERVER_ADMIN\"]=> string(18) \"[no address given]\" [\"SCRIPT_FILENAME\"]=> string(33) \"H:/Domains/galtrade.loc/index.php\" [\"REMOTE_PORT\"]=> string(5) \"45846\" [\"GATEWAY_INTERFACE\"]=> string(7) \"CGI/1.1\" [\"SERVER_PROTOCOL\"]=> string(8) \"HTTP/1.1\" [\"REQUEST_METHOD\"]=> string(3) \"GET\" [\"QUERY_STRING\"]=> string(0) \"\" [\"REQUEST_URI\"]=> string(1) \"/\" [\"SCRIPT_NAME\"]=> string(10) \"/index.php\" [\"PHP_SELF\"]=> string(10) \"/index.php\" [\"REQUEST_TIME_FLOAT\"]=> float(1552820558.246) [\"REQUEST_TIME\"]=> int(1552820558) [\"argv\"]=> array(0) {sddsdsd } [\"argc\"]= int(0) }"

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 SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html