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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = ",?\\s?(\"[^\"]*,[^\"]*\"|[^\",]*)"; final String string = "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,,,,,,,,,,\n" + "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,,,,,,,,,,\n" + "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,,,,,,,,,,\n" + "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,,,,,,,,,,\n" + "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,,,,,,,,,,\n" + "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,,,,,,,,,,\n" + "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,,,,,,,,,,\n" + "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,,,,,,,,,,"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html