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

/
/
gm

Test String

Code Generator

Generated Code

const regex = /,?\s?("[^"]*,[^"]*"|[^",]*)/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp(',?\\s?("[^"]*,[^"]*"|[^",]*)', 'gm') const str = `St. Lawrence County,NY,,2,,Attainment Plan/Maintenance Plan,37,,1852,Nonattainment,,,,11922,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,2,,5,,0,0,,,,,,,,,,,,,,11922,,,,St. Lawrence County,4700,NY,NY,SO2.2010.St_Lawrence_Co,SO2.2010.St_Lawrence_Co.NY,,,,,,,,,, Howard County,TX,,6,,Attainment Plan/Maintenance Plan,37,,1853,Nonattainment,,,,281,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,6,,5,,0,0,,,,,,,,,,,,,,281,,,,Howard County,4710,TX,TX,SO2.2010.Howard_Co,SO2.2010.Howard_Co.TX,,,,,,,,,, Hutchinson County,TX,,6,,Attainment Plan/Maintenance Plan,37,,1854,Nonattainment,,,,14593,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,6,,5,,0,0,,,,,,,,,,,,,,14593,,,,Hutchinson County,4720,TX,TX,SO2.2010.Hutchinson_Co,SO2.2010.Hutchinson_Co.TX,,,,,,,,,, Navarro County,TX,,6,,Attainment Plan/Maintenance Plan,37,,1855,Nonattainment,,,,1593,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,6,,5,,0,0,,,,,,,,,,,,,,1593,,,,Navarro County,4730,TX,TX,SO2.2010.Navarro_Co,SO2.2010.Navarro_Co.TX,,,,,,,,,, Giles County,VA,,3,,Attainment Plan/Maintenance Plan,37,,1856,Nonattainment,,,,183,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,3,,5,,0,0,,,,,,,,,,,,,,183,,,,Giles County,4740,VA,VA,SO2.2010.Giles_Co,SO2.2010.Giles_Co.VA,,,,,,,,,, New Madrid County,MO,,7,,Attainment Plan/Maintenance Plan,37,,1851,Nonattainment,,,,2,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,7,,5,,0,0,,,,,,,,,,,,,,2,,,,New Madrid County,4690,MO,MO,SO2.2010.New_Madrid_Co,SO2.2010.New_Madrid_Co.MO,,,,,,,,,, Henderson-Webster Counties,KY,,4,,Attainment Plan/Maintenance Plan,37,,1850,Nonattainment,,,,6932,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,4,,5,,0,0,,,,,,,,,,,,,,6932,,,,Henderson-Webster Counties,4680,KY,KY,SO2.2010.Henderson_Webster_Cos,SO2.2010.Henderson_Webster_Cos.KY,,,,,,,,,, Whatcom County,WA,,10,,Attainment Plan/Maintenance Plan,37,,1857,Nonattainment,,,,32,,,4/30/2021,4/30/2026,ppm,,,,,,,,,,,,,,,,,,,10,,5,,0,0,,,,,,,,,,,,,,32,,,,Whatcom County,4750,WA,WA,SO2.2010.Whatcom_Co,SO2.2010.Whatcom_Co.WA,,,,,,,,,,`; // 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