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
No Match

/
/
gi

Test String

Code Generator

Generated Code

const regex = /(#)(?:([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?|([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])?)|(rgb|rgba)\((?:\s*(0*(?:0|1[0-9]{0,2}|2(?:[0-4][0-9]?|5[0-4]?|[6-9])?|[3-9][0-9]?)(?:\.[0-9]+)?|255(?:\.0+)?|\.[0-9]+)\s*,\s*(0*(?:0|1[0-9]{0,2}|2(?:[0-4][0-9]?|5[0-4]?|[6-9])?|[3-9][0-9]?)(?:\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\/)\s*(0*(?:(?:0|[1-9][0-9]?)(?:\.[0-9]+)?|100(?:\.0+)?|\.[0-9]+)%|0*0*(?:\.[0-9]+)?|1(?:\.0+)?|\.[0-9]+))?\s*)?|(xyz|xyz-d50|xyz-d65)(?:\s+|\s*,\s*)(-?[0-9]+(?:\.[0-9]+)?%?)(?:\s+|\s*,\s*)(-?[0-9]+(?:\.[0-9]+)?%?)(?:\s+|\s*,\s*)(-?[0-9]+(?:\.[0-9]+)?%?)(?:(?:\s+\s*(?:\/)\s*(0*(?:(?:0|[1-9][0-9]?)(?:\.[0-9]+)?|100(?:\.0+)?|\.[0-9]+)%|0*0*(?:\.[0-9]+)?|1(?:\.0+)?|\.[0-9]+))?\s*)?)\)|(yellowgreen|yellow|whitesmoke|white|wheat|VisitedText|violet|turquoise|transparent|tomato|thistle|teal|tan|steelblue|springgreen|snow|slategrey|slategray|slateblue|skyblue|silver|sienna|SelectedItemText|SelectedItem|seashell|seagreen|sandybrown|salmon|saddlebrown|royalblue|rosybrown|red|rebeccapurple|purple|powderblue|plum|pink|peru|peachpuff|papayawhip|palevioletred|paleturquoise|palegreen|palegoldenrod|orchid|orangered|orange|olivedrab|olive|oldlace|navy|navajowhite|moccasin|mistyrose|mintcream|midnightblue|mediumvioletred|mediumturquoise|mediumspringgreen|mediumslateblue|mediumseagreen|mediumpurple|mediumorchid|mediumblue|mediumaquamarine|maroon|MarkText|Mark|magenta|LinkText|linen|limegreen|lime|lightyellow|lightsteelblue|lightslategrey|lightslategray|lightskyblue|lightseagreen|lightsalmon|lightpink|lightgrey|lightgreen|lightgray|lightgoldenrodyellow|lightcyan|lightcoral|lightblue|lemonchiffon|lawngreen|lavenderblush|lavender|khaki|ivory|indigo|indianred|hotpink|honeydew|HighlightText|Highlight|grey|greenyellow|green|GrayText|gray|goldenrod|gold|ghostwhite|gainsboro|fuchsia|forestgreen|floralwhite|firebrick|FieldText|Field|dodgerblue|dimgrey|dimgray|deepskyblue|deeppink|darkviolet|darkturquoise|darkslategrey|darkslategray|darkslateblue|darkseagreen|darksalmon|darkred|darkorchid|darkorange|darkolivegreen|darkmagenta|darkkhaki|darkgrey|darkgreen|darkgray|darkgoldenrod|darkcyan|darkblue|cyan|currentColor|crimson|cornsilk|cornflowerblue|coral|chocolate|chartreuse|CanvasText|Canvas|cadetblue|ButtonText|ButtonFace|ButtonBorder|burlywood|brown|blueviolet|blue|blanchedalmond|black|bisque|beige|azure|aquamarine|aqua|antiquewhite|aliceblue|ActiveText|AccentColorText|AccentColor)/gi; // Alternative syntax using RegExp constructor // const regex = new RegExp('(#)(?:([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?|([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])?)|(rgb|rgba)\\((?:\\s*(0*(?:0|1[0-9]{0,2}|2(?:[0-4][0-9]?|5[0-4]?|[6-9])?|[3-9][0-9]?)(?:\\.[0-9]+)?|255(?:\\.0+)?|\\.[0-9]+)\\s*,\\s*(0*(?:0|1[0-9]{0,2}|2(?:[0-4][0-9]?|5[0-4]?|[6-9])?|[3-9][0-9]?)(?:\\.[0-9]+)?|255(?:\\.0+)?|\\.[0-9]+)\\s*,\\s*(0*(?:0|1[0-9]{0,2}|2(?:[0-4][0-9]?|5[0-4]?|[6-9])?|[3-9][0-9]?)(?:\\.[0-9]+)?|255(?:\\.0+)?|\\.[0-9]+)(?:\\s*,\\s*(0*(?:(?:0|[1-9][0-9]?)(?:\\.[0-9]+)?|100(?:\\.0+)?|\\.[0-9]+)%|0*0*(?:\\.[0-9]+)?|1(?:\\.0+)?|\\.[0-9]+))?\\s*|\\s*(0*(?:0|1[0-9]{0,2}|2(?:[0-4][0-9]?|5[0-4]?|[6-9])?|[3-9][0-9]?)(?:\\.[0-9]+)?|255(?:\\.0+)?|\\.[0-9]+)\\s+(0*(?:0|1[0-9]{0,2}|2(?:[0-4][0-9]?|5[0-4]?|[6-9])?|[3-9][0-9]?)(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\s*,\\s*)(-?[0-9]+(?:\\.[0-9]+)?%?)(?:\\s+|\\s*,\\s*)(-?[0-9]+(?:\\.[0-9]+)?%?)(?:\\s+|\\s*,\\s*)(-?[0-9]+(?:\\.[0-9]+)?%?)(?:(?:\\s+\\s*(?:\\\/)\\s*(0*(?:(?:0|[1-9][0-9]?)(?:\\.[0-9]+)?|100(?:\\.0+)?|\\.[0-9]+)%|0*0*(?:\\.[0-9]+)?|1(?:\\.0+)?|\\.[0-9]+))?\\s*)?)\\)|(yellowgreen|yellow|whitesmoke|white|wheat|VisitedText|violet|turquoise|transparent|tomato|thistle|teal|tan|steelblue|springgreen|snow|slategrey|slategray|slateblue|skyblue|silver|sienna|SelectedItemText|SelectedItem|seashell|seagreen|sandybrown|salmon|saddlebrown|royalblue|rosybrown|red|rebeccapurple|purple|powderblue|plum|pink|peru|peachpuff|papayawhip|palevioletred|paleturquoise|palegreen|palegoldenrod|orchid|orangered|orange|olivedrab|olive|oldlace|navy|navajowhite|moccasin|mistyrose|mintcream|midnightblue|mediumvioletred|mediumturquoise|mediumspringgreen|mediumslateblue|mediumseagreen|mediumpurple|mediumorchid|mediumblue|mediumaquamarine|maroon|MarkText|Mark|magenta|LinkText|linen|limegreen|lime|lightyellow|lightsteelblue|lightslategrey|lightslategray|lightskyblue|lightseagreen|lightsalmon|lightpink|lightgrey|lightgreen|lightgray|lightgoldenrodyellow|lightcyan|lightcoral|lightblue|lemonchiffon|lawngreen|lavenderblush|lavender|khaki|ivory|indigo|indianred|hotpink|honeydew|HighlightText|Highlight|grey|greenyellow|green|GrayText|gray|goldenrod|gold|ghostwhite|gainsboro|fuchsia|forestgreen|floralwhite|firebrick|FieldText|Field|dodgerblue|dimgrey|dimgray|deepskyblue|deeppink|darkviolet|darkturquoise|darkslategrey|darkslategray|darkslateblue|darkseagreen|darksalmon|darkred|darkorchid|darkorange|darkolivegreen|darkmagenta|darkkhaki|darkgrey|darkgreen|darkgray|darkgoldenrod|darkcyan|darkblue|cyan|currentColor|crimson|cornsilk|cornflowerblue|coral|chocolate|chartreuse|CanvasText|Canvas|cadetblue|ButtonText|ButtonFace|ButtonBorder|burlywood|brown|blueviolet|blue|blanchedalmond|black|bisque|beige|azure|aquamarine|aqua|antiquewhite|aliceblue|ActiveText|AccentColorText|AccentColor)', 'gi') const str = `#090 #009900 #090a #009900aa rgb(34, 12, 64, 0.6) rgba(34, 12, 64, 0.6) rgb(34 12 64 / 0.6) rgba(34 12 64 / 0.3) rgb(34 12 64 / 60%) rgba(34.6 12 64 / 30%) hsl(30, 100%, 50%, 0.6) hsla(30, 100%, 50%, 0.6) hsl(30 100% 50% / 0.6) hsla(30 100% 50% / 0.6) hsl(30 100% 50% / 60%) hsla(30.2grad 100% 50% / 60%) hwb(90 10% 10%) hwb(90 10% 10% / 0.5) hwb(90deg 10% 10%) hwb(1.5708rad 60% 0%) hwb(0.25turn 0% 40% / 50%) lab(29.2345% 39.3825 20.0664) lab(52.2345 40.1645 59.9971) lab(60.2345 -5.3654 58.956) lab(62.2345% -34.9638 47.7721) lab(67.5345 -8.6911 -41.6019) lab(29.69% 44.888% -29.04%) lch(29.2345% 44.2 27) lch(52.2345% 72.2 56.2) lch(60.2345 59.2 95.2) lch(62.2345% 59.2 126.2) lch(67.5345% 42.5 258.2) lch(29.69% 45.553% 327.1) oklab(40.101% 0.1147 0.0453) oklab(59.686% 0.1009 0.1192) oklab(0.65125 -0.0320 0.1274) oklab(66.016% -0.1084 0.1114) oklab(72.322% -0.0465 -0.1150) oklab(42.1% 41% -25%) oklch(40.101% 0.12332 21.555) oklch(59.686% 0.15619 49.7694) oklch(0.65125 0.13138 104.097) oklch(0.66016 0.15546 134.231) oklch(72.322% 0.12403 247.996) oklch(42.1% 48.25% 328.4) color(srgb 100% 100% 100% / 100%) color(xyz 999 999 999 / 100%) yellowgreen yellow whitesmoke white wheat violet turquoise tomato thistle teal tan steelblue springgreen snow slategrey slategray slateblue skyblue silver sienna seashell seagreen sandybrown salmon saddlebrown royalblue rosybrown red rebeccapurple purple powderblue plum pink peru peachpuff papayawhip palevioletred paleturquoise palegreen palegoldenrod orchid orangered orange olivedrab olive oldlace navy navajowhite moccasin mistyrose mintcream midnightblue mediumvioletred mediumturquoise mediumspringgreen mediumslateblue mediumseagreen mediumpurple mediumorchid mediumblue mediumaquamarine maroon magenta linen limegreen lime lightyellow lightsteelblue lightslategrey lightslategray lightskyblue lightseagreen lightsalmon lightpink lightgrey lightgreen lightgray lightgoldenrodyellow lightcyan lightcoral lightblue lemonchiffon lawngreen lavenderblush lavender khaki ivory indigo indianred hotpink honeydew grey greenyellow green gray goldenrod gold ghostwhite gainsboro fuchsia forestgreen floralwhite firebrick dodgerblue dimgrey dimgray deepskyblue deeppink darkviolet darkturquoise darkslategrey darkslategray darkslateblue darkseagreen darksalmon darkred darkorchid darkorange darkolivegreen darkmagenta darkkhaki darkgrey darkgreen darkgray darkgoldenrod darkcyan darkblue cyan crimson cornsilk cornflowerblue coral chocolate chartreuse cadetblue burlywood brown blueviolet blue blanchedalmond black bisque beige azure aquamarine aqua antiquewhite aliceblue Canvas CanvasText LinkText VisitedText ActiveText ButtonFace ButtonText ButtonBorder Field FieldText Highlight HighlightText SelectedItem SelectedItemText Mark MarkText GrayText AccentColor AccentColorText currentColor transparent `; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions