Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

$re = '/#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/'; $str = '<?xml version="1.0" encoding="iso-8859-1"?> <!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 297.001 297.001" style="enable-background:new 0 0 297.001 297.001;" xml:space="preserve"> <g> <path style="fill:#741258;" d="M148.494,106.91c-22.931,0-41.586,18.656-41.586,41.586s18.656,41.586,41.586,41.586 s41.586-18.656,41.586-41.586S171.425,106.91,148.494,106.91z"/> <g> <path style="fill:#FF0000;" d="M267.386,115.898c-2.261,0-4.48,0.923-6.091,2.524c-1.602,1.602-2.524,3.821-2.524,6.091 c0,2.271,0.923,4.49,2.524,6.091c1.611,1.611,3.831,2.524,6.091,2.524c2.271,0,4.49-0.913,6.091-2.524 c1.611-1.602,2.524-3.821,2.524-6.091c0-2.261-0.913-4.49-2.524-6.091C271.876,116.821,269.657,115.898,267.386,115.898z"/> <path style="fill:#86C867;" d="M170.793,259.485c-2.261,0-4.48,0.923-6.091,2.524c-1.602,1.602-2.524,3.821-2.524,6.091 c0,2.271,0.923,4.49,2.524,6.091c1.611,1.611,3.831,2.524,6.091,2.524c2.271,0,4.49-0.913,6.091-2.524 c1.611-1.602,2.524-3.821,2.524-6.091c0-2.261-0.913-4.49-2.524-6.091C175.283,260.407,173.064,259.485,170.793,259.485z"/> <path style="fill:#86C867;" d="M210.638,86.352c-15.051-15.051-30.842-28.617-46.802-40.317 c13.136-8.154,26.173-14.818,38.756-19.742c30.943-12.108,55.702-12.044,67.926,0.179c12.439,12.438,12.297,37.72-0.39,69.361 c-1.771,4.417,0.374,9.432,4.791,11.203c4.418,1.772,9.432-0.374,11.203-4.791c15.603-38.913,14.388-70.15-3.419-87.958 c-17.541-17.541-48.222-18.975-86.39-4.041c-15.537,6.08-31.671,14.601-47.818,25.152c-16.147-10.551-32.282-19.072-47.819-25.152 c-38.17-14.936-68.848-13.5-86.389,4.041s-18.976,48.221-4.041,86.389c6.08,15.537,14.601,31.671,25.152,47.818 c-10.551,16.147-19.073,32.282-25.153,47.819c-14.936,38.168-13.5,68.848,4.041,86.39c9.51,9.509,22.88,14.285,39.215,14.285 c13.792,0,29.701-3.408,47.176-10.245c35.867-14.035,74.918-41.064,109.961-76.106c15.032-15.032,28.573-30.77,40.382-46.911 c30.113,48.389,36.339,89.951,19.499,106.791c-12.438,12.438-37.72,12.298-69.361-0.39c-4.417-1.772-9.432,0.375-11.203,4.791 c-1.771,4.417,0.374,9.432,4.791,11.203c18.11,7.26,34.552,10.879,48.758,10.878c16.318-0.001,29.68-4.778,39.201-14.297 c17.54-17.542,18.975-48.222,4.04-86.39C272.708,160.447,245.681,121.395,210.638,86.352z M26.292,94.398 c-12.109-30.945-12.044-55.703,0.179-67.926c12.222-12.223,36.981-12.288,67.926-0.179c12.583,4.924,25.62,11.588,38.756,19.742 c-15.96,11.7-31.751,25.267-46.803,40.318c-15.051,15.051-28.617,30.842-40.317,46.802 C37.88,120.018,31.216,106.981,26.292,94.398z M26.471,270.519c-16.84-16.839-10.616-58.397,19.492-106.781 c11.716,15.993,25.308,31.818,40.389,46.9c15.032,15.031,30.77,28.572,46.91,40.382C84.874,281.134,43.311,287.36,26.471,270.519z M198.452,198.454c-16.73,16.73-33.557,30.837-49.85,42.365c-17.231-12.125-34.052-26.352-50.065-42.365 c-16.108-16.108-30.408-33.043-42.384-50.041c11.532-16.301,25.644-33.137,42.383-49.876 c16.082-16.082,32.988-30.362,49.959-42.327c16.97,11.964,33.877,26.244,49.959,42.326c16.73,16.73,30.837,33.558,42.365,49.851 C228.693,165.619,214.466,182.44,198.452,198.454z"/> </g> <path style="fill:#293E4F;" d="M148.494,106.91c-0.283,0-0.563,0.016-0.844,0.021v83.13c0.282,0.006,0.561,0.021,0.844,0.021 c22.931,0,41.586-18.656,41.586-41.586S171.425,106.91,148.494,106.91z"/> <g> <path style="fill:#6CAA4B;" d="M267.386,115.898c-2.261,0-4.48,0.923-6.091,2.524c-1.602,1.602-2.524,3.821-2.524,6.091 c0,2.271,0.923,4.49,2.524,6.091c1.611,1.611,3.831,2.524,6.091,2.524c2.271,0,4.49-0.913,6.091-2.524 c1.611-1.602,2.524-3.821,2.524-6.091c0-2.261-0.913-4.49-2.524-6.091C271.876,116.821,269.657,115.898,267.386,115.898z"/> <path style="fill:#6CAA4B;" d="M170.793,259.485c-2.261,0-4.48,0.923-6.091,2.524c-1.602,1.602-2.524,3.821-2.524,6.091 c0,2.271,0.923,4.49,2.524,6.091c1.611,1.611,3.831,2.524,6.091,2.524c2.271,0,4.49-0.913,6.091-2.524 c1.611-1.602,2.524-3.821,2.524-6.091c0-2.261-0.913-4.49-2.524-6.091C175.283,260.407,173.064,259.485,170.793,259.485z"/> <path style="fill:#6CAA4B;" d="M210.638,86.352c-15.051-15.051-30.842-28.617-46.802-40.317 c13.136-8.154,26.173-14.818,38.756-19.742c30.943-12.108,55.702-12.044,67.926,0.179c12.439,12.438,12.297,37.72-0.39,69.361 c-1.771,4.417,0.374,9.432,4.791,11.203c4.418,1.772,9.432-0.374,11.203-4.791c15.603-38.913,14.388-70.15-3.419-87.958 c-17.541-17.541-48.222-18.975-86.39-4.041c-15.537,6.08-31.671,14.601-47.818,25.152c-0.282-0.184-0.563-0.356-0.845-0.539 v21.962c0.282-0.2,0.563-0.412,0.845-0.61c16.97,11.964,33.877,26.244,49.959,42.326c16.73,16.73,30.837,33.558,42.365,49.851 c-12.126,17.232-26.352,34.053-42.366,50.066c-16.73,16.73-33.557,30.837-49.85,42.365c-0.318-0.224-0.634-0.461-0.952-0.687 v22.006c21.41-13.896,42.86-31.372,62.988-51.5c15.032-15.032,28.573-30.77,40.382-46.911 c30.113,48.389,36.339,89.951,19.499,106.791c-12.438,12.438-37.72,12.298-69.361-0.39c-4.417-1.772-9.432,0.375-11.203,4.791 c-1.771,4.417,0.374,9.432,4.791,11.203c18.11,7.26,34.552,10.879,48.758,10.878c16.318-0.001,29.68-4.778,39.201-14.297 c17.54-17.542,18.975-48.222,4.04-86.39C272.708,160.447,245.681,121.395,210.638,86.352z"/> </g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> </svg>'; 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