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

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