Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
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 = "(?m)^[\\+]{0,1}(\\d+),\\d+,[\\s\\d\\w\\*\\-]*,([\\d\\w]*),[\\d\\/\\-]*,[\\d\\.\\-]*,[\\d\\.\\-]*,([\\w]{0,3}),[\\d\\/\\.\\-]*,[\\d\\w]*,(\\d{0,4}),.*$"; final String string = "\n" + "28145518,3180,CA,PON,02/06/19,11435.95,0.00,CCR,,593,,,\n" + "26363071,3184,OH,P35,06/13/18,2501.45,0.00,CCR,,584,,,\n" + "+30242134,3291,MD,DNC,10/09/19,-7.49,0.00,CPF,,18910,,\n" + "28487956,3174,TX,PLP,04/01/19,1925.72,0.00,CCR,,787,,,\n" + "26253584,3198,TX,HB3,06/01/18,5922.38,0.00,CCR,,654,,,\n" + "27370866,3178,VA,PCR,10/31/18,1266.89,0.00,CCR,,670,,,\n" + "26815747,3184,MO,P35,08/09/18,3636.76,0.00,CCR,169,640,,,\n" + "26258531,3172,HI,H5,06/01/18,218.59,218.59,CPF,,775,,,\n" + "26035753,3174,MS,PLP,05/01/18,4727.00,0.00,CCR,,751,,,\n" + "26818709,3186,CA,P35,08/10/18,5076.83,0.00,CCR,,565,,,\n" + "28496226,3197,MA,09,04/02/19,1428.70,0.00,CAT,,664,,,\n" + "26486481,3182,CA,P35,07/03/18,1037.80,0.00,CCR,,690,,,\n" + "26933980,3194,CA,P35,08/31/18,16660.38,0.00,CCR,,665,,,\n" + "28499032,3184,MI,YXH,04/02/19,384.87,0.00,CCR,,658,,,\n" + "26266894,3194,NY,P35,06/03/18,1004.78,0.00,CCR,,663,,,\n" + "25933151,3181,NY,P35,04/11/18,573.41,0.00,CCR,,636,,,\n" + "27164083,3174,CA,P32,10/01/18,1977.55,0.00,CCR,,667,,,\n" + "25825695,3181,CA,P35,03/31/18,1530.02,0.00,CCR,,599,,,\n" + "26945425,3180,AR,348,08/31/18,4866.12,487.00,CSF,,659,,,\n" + "28510870,3184,FL,PON,04/03/19,1629.65,0.00,CCR,,625,,,\n" + "27170241,3194,OR,PCR,10/02/18,3485.47,0.00,CCR,,669,,,\n" + "26264559,3194,CA,CW2,06/03/18,1962.67,0.00,CCR,,624,,,\n" + "28840633,3174,IL,PHH,06/02/19,6044.55,0.00,CCR,,746,,00006272,\n" + "28513665,3194,MI,XP3,04/03/19,15919.45,0.00,CCR,,689,,,\n" + "28844923,3172,GA,PHH,06/02/19,2075.56,0.00,CCR,,692,,,\n" + "28696703,3182,WA,RSP,05/03/19,4196.24,0.00,CCR,,573,,00006272, \n\n" + "26291742,3258,GA,TDU,06/04/18,17638.54,,CCR,,700,1679,P405, \n" + "('2019-04-30', 25268769, 'TDU', 'CAT', 1718),\n" + "28001929,2680,NJ,OPH,01/18/19,3391.96,,0,,740,,\n" + "29324631,3356,VA,GGH,06/04/19,485.00,,,,,, \n" + "29302464,3356,MD,GGH,06/04/19,589.00,,,,,, \n" + "29302841,3356,MD,GGH,06/04/19,25.00,,,,,, \n" + "29302844,3356,MD,GGH,06/04/19,290.00,,,,,, \n" + "29306713,3356,MD,GGH,06/04/19,101.49,,,,,, \n" + "29312194,3356,DC,GGH,06/04/19,391.00,,,,,, \n" + "29313169,3356,MD,GGH,06/04/19,281.00,,,,,, \n" + "29315068,3356,MD,GGH,06/04/19,483.03,,,,,, \n" + "29303328,3356,MD,GGH,06/04/19,405.94,,,,,, \n" + "29306716,3356,MD,GGH,06/04/19,149.09,,,,,, \n" + "29319211,3356,MD,GGH,06/04/19,43.39,,,,,, \n" + "29348236,3352,-1,FOR,06/12/19,3252.00,,FOR,,716,, \n" + "29437391,3352,-2,FOR,03/15/19,429.39,,FOR,,690,, \n\n" + "27402066,3174,AZ,NLP,11/01/18,5632.13,0.00,CCR,,734,,00006272 \n" + "25296064,3285,NY,Q07,01/12/18,1066.55,,CCR,,X,,\n" + "25192424,3285,**,Q07,12/12/17,779.51,,CCR,,X,, \n" + "25268778,3258,CA,TDU,01/04/18,10725.18,,CCR,,724,,P102, \n" + "27221738,3258,VA,TDU,10/03/18,14673.35,,CCR,,743,,, \n" + "27028597,3186,AZ,,09/10/18,5928.92,,CCR,,713,,,\n" + "25268778,3258,CA,TDU,01/04/18,10725.18,,CCR,,724,1605,P102, \n" + "27221738,3258,VA,TDU,10/03/18,14673.35,,CCR,,743,1727,P202, \n" + "25082803,3258,CA,DSA,12/04/17,4844.55,,CAT,,18238,1607,P102, \n" + "25082815,3258,NY,TDU,12/04/17,7708.50,,CAT,,757,1568,P202, \n" + "25082803,3258,CA,DSA,12/04/17,4844.55,,CAT,,18238,1607,P102, \n" + "25082815,3258,NY,TDU,12/04/17,7708.50,,CAT,,757,1568,P202, \n" + "('2019-04-30', 26291799, 'TDU', 'CSF', 1692),\n" + "28291256,3214,TX,DTA,03/04/19,559.29,,DSA,,579,1182,P402, \n" + "26291810,3258,TN,TDU,06/04/18,4121.16,,CCR,,675,1679,P202, \n" + "27221806,3258,MO,TDU,10/03/18,3794.67,,CCR,,18541,1512,P101, \n" + "28291285,3214,NY,BRH,03/04/19,1306.25,,ACT,,18693,1455,P201, \n" + "25082869,3258,TX,X98,12/04/17,2472.30,,CCR,,642,1581,P202, \n" + "('2019-04-30', 26291854, 'DS1', 'CSF', 1718),\n" + "25082890,3258,CA,TDU,12/04/17,5508.37,,CCR,,18238,1512,P202, \n" + "26756854,3215,MD,TDU,08/03/18,344.68,,CCR,,714,1529,P203, \n" + "25268888,3258,MI,TDU,01/04/18,8719.17,,CAT,,18269,1324,P405, \n" + "25082893,3258,GA,TDU,12/04/17,10688.96,,CCR,,695,1512,P302, \n" + "25268894,3258,OR,TDU,01/04/18,9721.14,,CCR,,668,1441,P102, \n" + "25082906,3258,TX,TDU,12/04/17,21740.57,,CAT,,706,1619,P405, \n" + "27221874,3258,MA,TDU,10/03/18,2781.90,,CCR,,707,1616,P405, \n" + "('2019-04-30', 27221877, 'TDU', 'CCR', 1524),\n" + "25268920,3258,NJ,TDU,01/04/18,5824.38,,CCR,,721,1667,P406, \n" + "25082927,3258,NJ,TDU,12/04/17,6228.66,,CAT,,18238,1529,P202, \n" + "27221882,3258,PA,DSA,10/03/18,5460.58,,DSA,,692,1824,P303, \n" + "25268938,3258,GA,DSA,01/04/18,5945.14,,CCR,,660,1512,P101, \n" + "27221907,3258,NJ,TDU,10/03/18,10904.41,,CCR,,651,1916,P101, \n" + "25082966,3258,TX,TDU,12/04/17,7440.78,,CCR,,697,1535,P303, \n" + "('2019-04-30', 24710985, 'TDU', 'CSF', 1528),\n" + "26291955,3258,NY,665,06/04/18,8605.74,,ATY,,607,1589,P101, \n" + "('2019-04-30', 24710995, 'TDU', 'DSA', 1534),\n"; 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