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

/
/
gm

Test String

Substitution

Processing...

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 = "^(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)$"; final String string = "0001,213593,0216111117218625,12,61,49\n" + "0002,215083,17011696289579,16,64,48\n" + "0003,217524,17010300818741,3,49,46\n" + "0004,208995,0015713000295713,9,52,43\n" + "0005,164523,2000854,13,55,42\n" + "0006,142653,2001624,2,42,40\n" + "0007,199623,2000031,14,54,40\n" + "0008,214125,17012070897588,5,45,40\n" + "0009,218171,0019653000299658,7,47,40\n" + "0010,201166,0116110626935058,3,42,39\n" + "0011,218110,17012051222092,1,39,38\n" + "0012,201531,0000003000210563,11,47,36\n" + "0013,205233,0074983000354981,6,41,35\n" + "0014,190888,2000043,71,105,34\n" + "0015,150291,1017196,3,35,32\n" + "0016,210599,0016333000296331,46,78,32\n" + "0017,205501,0044273000324273,8,39,31\n" + "0018,206686,0066073000346078,60,91,31\n" + "0019,154672,2000223,28,58,30\n" + "0020,178095,0000003000132288,3,33,30\n" + "0021,207086,17010587343512,1,31,30\n" + "0022,217841,17010813318391,36,64,28\n" + "0023,207181,2000023,1,28,27\n" + "0024,204165,0131363000411369,72,98,26\n" + "0025,206818,0067993000347993,11,37,26\n" + "0026,210035,0004163000284162,26,52,26\n" + "0027,147887,0114763000394763,1,26,25\n" + "0028,202350,0000003000229217,23,48,25\n" + "0029,145309,1014590,24,48,24\n" + "0030,159330,1053129,12,36,24\n" + "0031,204130,0000003000273801,17,41,24\n" + "0032,209986,0005843000285847,16,39,23\n" + "0033,210352,17010376723300,63,85,22\n" + "0034,201594,0000003000211835,4,25,21\n" + "0035,202862,17010979764841,7,28,21\n" + "0036,215805,17010165946544,15,36,21\n" + "0037,143241,1019128,10,30,20\n" + "0038,143312,1017129,14,34,20\n" + "0039,149576,1026226,3,23,20\n" + "0040,156694,1018449,176,196,20\n" + "0041,197264,1026220,12,32,20\n" + "0042,200702,1021143,4,24,20\n" + "0043,202887,0000003000219820,26,46,20\n" + "0044,208217,0000003000222220,11,31,20\n" + "0045,213688,0038973000318978,8,28,20\n" + "0046,213773,17011268393085,51,71,20\n" + "0047,218607,17010242119979,46,66,20\n" + "0048,191062,0000003000068623,5,24,19\n" + "0049,196971,2002097,44,63,19\n" + "0050,205238,0000003000268892,5,24,19\n" + "0051,206538,0043673000323671,27,46,19\n" + "0052,212046,0028143000308144,32,51,19\n" + "0053,203041,0000003000213930,43,61,18\n" + "0054,204164,0131843000411849,11,29,18\n" + "0055,205491,0045943000325940,48,66,18\n" + "0056,210043,0000003000217048,55,73,18\n" + "0057,217060,17010427785128,8,26,18\n" + "0058,218302,17010585320870,4,22,18\n" + "0059,129889,2000296,5,22,17\n" + "0060,154809,2002429,221,238,17\n" + "0061,161240,0000002000005114,54,71,17\n" + "0062,210249,0056883000336889,49,66,17\n" + "0063,218459,0025663000305660,5,22,17\n" + "0064,218650,17010092080098,13,30,17\n" + "0065,220581,0116111061690833,3,20,17\n" + "0066,210482,0021213000301214,7,23,16\n" + "0067,214284,17010042091926,18,34,16\n" + "0068,151677,0092613000372611,43,58,15\n" + "0069,208979,0015133000295135,2,17,15\n" + "0070,213068,0216110606422697,19,34,15\n" + "0071,214675,17011267144402,15,30,15\n" + "0072,149456,0019903000299905,3,17,14\n" + "0073,159448,0000003000169785,17,31,14\n" + "0074,212363,0013913000293916,6,20,14\n" + "0075,212555,0078103000358107,30,44,14\n" + "0076,215966,0018983000298980,92,106,14\n" + "0077,162669,1015500,1,14,13\n" + "0078,178643,0000002000000123,20,33,13\n" + "0079,199619,1000474,20,33,13\n" + "0080,202165,0000003000227195,31,44,13\n" + "0081,209217,0000003000231577,38,51,13\n" + "0082,214203,17011076190285,21,34,13\n" + "0083,181436,0000003000254132,21,33,12\n" + "0084,201713,0135593000415592,14,26,12\n" + "0085,205494,0000003000237269,22,34,12\n" + "0086,208393,0055693000335691,38,50,12\n" + "0087,208740,0027693000307690,40,52,12\n" + "0088,210159,0005483000285482,41,53,12\n" + "0089,211397,0031833000311833,32,44,12\n" + "0090,213000,0216111558671208,28,40,12\n" + "0091,140145,1053604,17,28,11\n" + "0092,148007,1016524,50,61,11\n" + "0093,164701,0002763000282760,99,110,11\n" + "0094,196966,0000002000010775,2,13,11\n" + "0095,200021,2000203,23,34,11\n" + "0096,204298,0130813000410817,10,21,11\n" + "0097,209404,0068773000348777,44,55,11\n" + "0098,211054,0017133000297131,34,45,11\n" + "0099,218441,17010920787485,3,14,11\n" + "0100,143785,1026468,8,18,10\n" + "0101,148901,0024503000304507,8,18,10\n" + "0102,199781,0077533000357539,43,53,10\n" + "0103,202554,0000003000229381,1,11,10\n" + "0104,203519,0146483000426482,1,11,10\n" + "0105,205966,0138073000418075,43,53,10\n" + "0106,207522,0063043000343042,24,34,10\n" + "0107,208453,0055493000335493,34,44,10\n" + "0108,209939,0033933000313938,3,13,10\n" + "0109,216513,0216111795848594,34,44,10\n" + "0110,218133,17010667026522,38,48,10\n" + "0111,218651,17010746471792,1,11,10\n" + "0112,129908,0000002000016822,39,48,9\n" + "0113,153933,0071553000351558,47,56,9\n" + "0114,177104,0000003000029401,53,62,9\n" + "0115,202182,0000003000226577,24,33,9\n" + "0116,205321,0048813000328811,21,30,9\n" + "0117,208798,0026463000306460,28,37,9\n" + "0118,209758,0056113000336111,15,24,9\n" + "0119,216746,17011060720857,61,70,9\n" + "0120,142872,2000290,169,177,8\n" + "0121,157435,1017115,15,23,8\n" + "0122,157458,2002327,115,123,8\n" + "0123,165285,0216110198332043,4,12,8\n" + "0124,179247,0000003000029476,487,495,8\n" + "0125,199816,2000267,18,26,8\n" + "0126,200081,2001773,86,94,8\n" + "0127,200739,0000003000278370,26,34,8\n" + "0128,202995,0000003000201646,45,53,8\n" + "0129,213160,0216111287407934,57,65,8\n" + "0130,213349,0216111563562536,7,15,8\n" + "0131,215161,0019013000299012,16,24,8\n" + "0132,131380,1026630,2,9,7\n" + "0133,137873,0000003000001871,9,16,7\n" + "0134,150830,0038273000318275,82,89,7\n" + "0135,151535,1027681,17,24,7\n" + "0136,156898,0101493000381497,45,52,7\n" + "0137,165010,2000948,25,32,7\n" + "0138,190362,2009456,18,25,7\n" + "0139,201978,0000003000227377,22,29,7\n" + "0140,202259,0000003000226668,88,95,7\n" + "0141,203446,0005863000285862,14,21,7\n" + "0142,208320,0054873000334876,39,46,7\n" + "0143,208747,0021203000301206,12,19,7\n" + "0144,209062,0014393000294393,12,19,7\n" + "0145,211268,0041693000321691,73,80,7\n" + "0146,211417,0031643000311643,1,8,7\n" + "0147,213745,17010601506423,5,12,7\n" + "0148,214412,0039613000319612,11,18,7\n" + "0149,214955,17010336291215,12,19,7\n" + "0150,215018,17011205821558,15,22,7\n" + "0151,215263,17011392447850,33,40,7\n" + "0152,216364,17011123508012,1,8,7\n" + "0153,148778,1025276,56,62,6\n" + "0154,155678,0119923000399929,42,48,6\n" + "0155,157000,2000331,90,96,6\n" + "0156,158494,1017192,17,23,6\n" + "0157,161151,0000003000277877,2,8,6\n" + "0158,171205,1026219,2,8,6\n" + "0159,180705,0000003000084208,127,133,6\n" + "0160,185561,0000003000096301,10,16,6\n" + "0161,191509,0000002000014967,32,38,6\n" + "0162,193859,2000660,10,16,6\n" + "0163,196277,0129943000409942,68,74,6\n" + "0164,199673,2000127,18,24,6\n" + "0165,199787,1001337,41,47,6\n" + "0166,199965,2000081,35,41,6\n" + "0167,200065,1000397,35,41,6\n" + "0168,201271,0000002000019776,44,50,6\n" + "0169,201562,0121123000401121,2,8,6\n" + "0170,201781,0000003000233714,18,24,6\n" + "0171,202585,0000003000200226,29,35,6\n" + "0172,204175,0000003000239042,21,27,6\n" + "0173,205535,0044333000324331,52,58,6\n" + "0174,205819,0044053000324050,2,8,6\n" + "0175,206334,0010603000290607,9,15,6\n" + "0176,207060,0145753000425758,12,18,6\n" + "0177,208187,0064273000344271,2,8,6\n" + "0178,209771,0032503000312500,6,12,6\n" + "0179,212310,0137783000417788,16,22,6\n" + "0180,212816,0216112085750606,21,27,6\n" + "0181,214919,17010516436241,31,37,6\n" + "0182,216765,17011475501967,50,56,6\n" + "0183,218155,17010503466362,4,10,6\n" + "0184,220053,17010597512233,14,20,6\n" + "0185,151665,1050950,35,40,5\n" + "0186,152660,1000358,14,19,5\n" + "0187,159770,0038703000318705,11,16,5\n" + "0188,159776,1012240,79,84,5\n" + "0189,162404,1021706,17,22,5\n" + "0190,166285,1010938,44,49,5\n" + "0191,173134,1026862,10,15,5\n" + "0192,178212,0000002000009983,1,6,5\n" + "0193,181065,0000003000005708,38,43,5\n" + "0194,185342,0000003000009270,30,35,5\n" + "0195,186955,0000003000202727,52,57,5\n" + "0196,199790,2000157,17,22,5\n" + "0197,201442,0019173000299178,86,91,5\n" + "0198,201608,0000003000211744,27,32,5\n" + "0199,201962,0000003000228169,34,39,5\n" + "0200,204827,0049743000329744,26,31,5\n" + "0201,208132,0054373000334371,12,17,5\n" + "0202,210797,1000824,33,38,5\n" + "0203,211507,0030543000310546,11,16,5\n" + "0204,212856,0078393000358396,47,52,5\n" + "0205,214551,17011403849637,1,6,5\n" + "0206,214939,17011012741719,1,6,5\n" + "0207,215945,17012096844180,25,30,5\n" + "0208,215992,17011733707680,30,35,5\n" + "0209,218734,17010646929086,14,19,5\n" + "0210,135580,0000002000017953,31,35,4\n" + "0211,141027,0000002000015923,97,101,4\n" + "0212,149798,1052055,21,25,4\n" + "0213,155320,0000003000273611,35,39,4\n" + "0214,155328,0082363000362364,7,11,4\n" + "0215,157682,0000003000257755,154,158,4\n" + "0216,163517,0085343000365342,20,24,4\n" + "0217,166802,2001793,36,40,4\n" + "0218,175962,0000003000022240,35,39,4\n" + "0219,178694,0000003000012613,36,40,4\n" + "0220,179089,2004435,20,24,4\n" + "0221,180177,0000002000000941,10,14,4\n" + "0222,180540,0000003000029500,38,42,4\n" + "0223,186575,1008281,7,11,4\n" + "0224,189087,1010926,1,5,4\n" + "0225,194806,0000003000013074,43,47,4\n" + "0226,195740,0000003000243622,34,38,4\n" + "0227,201792,0000003000233771,15,19,4\n" + "0228,205828,0044023000324026,14,18,4\n" + "0229,206726,0066123000346128,1,5,4\n" + "0230,207469,0063533000343539,44,48,4\n" + "0231,208097,0054443000334447,16,20,4\n" + "0232,210484,0017153000297157,43,47,4\n" + "0233,211143,0040413000320412,29,33,4\n" + "0234,211810,0028323000308326,13,17,4\n" + "0235,217522,0216111430087119,10,14,4\n" + "0236,219023,17011648982328,34,38,4\n" + "0237,220095,17011271275513,3,7,4\n" + "0238,141332,1005442,96,99,3\n" + "0239,145361,0000002000016129,67,70,3\n" + "0240,148336,2007930,24,27,3\n" + "0241,148861,0000003000243424,3,6,3\n" + "0242,149035,0092883000372884,25,28,3\n" + "0243,157778,0000003000002366,20,23,3\n" + "0244,168118,0000003000008694,68,71,3\n" + "0245,171505,0000003000192308,201,204,3\n" + "0246,177911,0000002000005064,1,4,3\n" + "0247,184942,0000003000090221,19,22,3\n" + "0248,194546,0000003000251427,5,8,3\n" + "0249,197387,1009251,22,25,3\n" + "0250,199695,2000375,1,4,3\n" + "0251,199713,2000545,18,21,3\n" + "0252,200125,1000107,11,14,3\n" + "0253,200723,1002063,36,39,3\n" + "0254,201505,0000003000232575,62,65,3\n" + "0255,201751,0135563000415568,17,20,3\n" + "0256,201817,0000003000233912,43,46,3\n" + "0257,201935,0000003000227401,44,47,3\n" + "0258,202053,0000003000229720,7,10,3\n" + "0259,202317,0134183000414181,36,39,3\n" + "0260,202449,0000003000229340,13,16,3\n" + "0261,202480,0000003000229563,21,24,3\n" + "0262,202669,0135313000415311,4,7,3\n" + "0263,204822,0048883000328886,10,13,3\n" + "0264,205641,0016903000296901,15,18,3\n" + "0265,206810,0067923000347928,20,23,3\n" + "0266,208743,0124493000404497,9,12,3\n" + "0267,208956,0014643000294641,20,23,3\n" + "0268,209788,0036773000316774,12,15,3\n" + "0269,210693,0021523000301529,25,28,3\n" + "0270,210958,0016053000296050,17,20,3\n" + "0271,211591,17011761020404,89,92,3\n" + "0272,212911,0216111892813579,9,12,3\n" + "0273,213556,1004433,12,15,3\n" + "0274,139939,1001202,10,12,2\n" + "0275,149942,1026346,12,14,2\n" + "0276,153680,0000003000273017,12,14,2\n" + "0277,154841,2000019,52,54,2\n" + "0278,179914,0000002000001056,22,24,2\n" + "0279,199666,1000867,13,15,2\n" + "0280,201685,0000003000210076,29,31,2\n" + "0281,202692,0000003000201471,3,5,2\n" + "0282,202771,0000003000234613,2,4,2\n" + "0283,203975,0007093000287090,14,16,2\n" + "0284,205270,0075773000355772,120,122,2\n" + "0285,205514,0045623000325627,36,38,2\n" + "0286,205553,0044633000324638,6,8,2\n" + "0287,205629,0045173000325171,21,23,2\n" + "0288,207041,0149933000429932,100,102,2\n" + "0289,207421,0008683000288684,20,22,2\n" + "0290,208000,0065913000345914,29,31,2\n" + "0291,208290,0064043000344040,104,106,2\n" + "0292,209174,0132963000412961,27,29,2\n" + "0293,210393,0005273000285276,18,20,2\n" + "0294,210860,0017433000297438,23,25,2\n" + "0295,212624,0079943000359949,1,3,2\n" + "0296,213162,0216110763901595,3,5,2\n" + "0297,214209,17010315101373,55,57,2\n" + "0298,214443,17011685002917,13,15,2\n" + "0299,214538,17010721561669,28,30,2\n" + "0300,215353,17011676022495,25,27,2\n" + "0301,216798,17011543054775,33,35,2\n" + "0302,216904,17011644970584,12,14,2\n" + "0303,217873,17010334046616,39,41,2\n" + "0304,217971,17010663105959,13,15,2\n" + "0305,218239,17011942243331,47,49,2\n" + "0306,130895,1055234,681,682,1\n" + "0307,137283,2008032,7,8,1\n" + "0308,139301,0000003000130290,46,47,1\n" + "0309,139866,0116013000396016,5,6,1\n" + "0310,140638,0000002000012805,28,29,1\n" + "0311,148197,0086343000366340,34,35,1\n" + "0312,155358,2007687,5,6,1\n" + "0313,156257,0109963000389961,42,43,1\n" + "0314,160293,0000002000014702,13,14,1\n" + "0315,160470,0000003000261772,21,22,1\n" + "0316,162896,1022531,141,142,1\n" + "0317,165004,0216110226451251,47,48,1\n" + "0318,177163,0000002000000925,4,5,1\n" + "0319,178540,0000002000001089,37,38,1\n" + "0320,179823,0000003000215258,13,14,1\n" + "0321,183080,0000003000143269,7,8,1\n" + "0322,199664,2000109,87,88,1\n" + "0323,199703,2000317,43,44,1\n" + "0324,201793,0000003000233789,97,98,1\n" + "0325,202535,0000003000234837,42,43,1\n" + "0326,207484,0063623000343620,31,32,1\n" + "0327,208072,0000003000275905,66,67,1\n" + "0328,210377,0000003000216172,41,42,1\n" + "0329,210550,0021553000301553,24,25,1\n" + "0330,210725,0017303000297305,16,17,1\n" + "0331,212828,0002183000282182,6,7,1\n" + "0332,213378,0216111311985463,5,6,1\n" + "0333,213640,0216111929581091,32,33,1\n" + "0334,214345,0039083000319083,1,2,1\n" + "0335,215081,17010621557580,6,7,1\n" + "0336,215773,17010898444387,27,28,1\n" + "0337,216956,17011132726270,18,19,1"; final String subst = "{\"url\":\"http://staging.elys.id/api/wallet/redeem/?$2-$3\", \"postData\": \"{\\\\\"instrumentUid\\\\\":\\\\\"$3\\\\\",\\\\\"referenceId\\\\\":\\\\\"CRM-FIX$1-2017-07-29-FIX\\\\\",\\\\\"createdDate\\\\\":\\\\\"2017-07-29T21:24:00.00\\\\\",\\\\\"redeem\\\\\":{\\\\\"type\\\\\":\\\\\"SP\\\\\",\\\\\"amount\\\\\":\\\\\"$6\\\\\",\\\\\"description\\\\\":\\\\\"Fixing point for $2-$3\\\\\"}}\"},"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceAll(subst); System.out.println("Substitution result: " + result); } }

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