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

r"
"
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?m)^(.*?)(,[A-Z]{3},.*)$" Local $sString = "Korea, Rep.,KOR,Population (Total),SP.POP.TOTL,25012374,25765673,26513030,27261747,27984155,28704674,29435571,30130983,30838302,31544266,32240827,32882704,33505406,34103149,34692266,35280725,35848523,36411795,36969185,37534236,38123775,38723248,39326352,39910403,40405956,40805744,41213674,41621690,42031247,42449038,42869283,43295704,43747962,44194628,44641540,45092991,45524681,45953580,46286503,46616677,47008111,47357362,47622179,47859311,48039415,48138077,48371946,48597652,48948698,49182038,49410366,49779440,50004441, - , - , - , - , - , - , - " & @CRLF & _ "Bermuda,BMU,Population (Total),SP.POP.TOTL,44400,45500,46600,47700,48900,50100,51000,52000,53000,54000,55000,54600,54200,53800,53400,53000,53200,53400,53600,53800,54670,55050,55449,55930,56423,56898,57382,57849,58347,58841,59326,59021,58595,58910,59320,59746,60129,60497,60943,61285,61833,62504,62912,63325,63740,64154,64523,64888,65273,65636,65124,64564,64806, - , - , - , - , - , - , - " & @CRLF & _ "Bolivia,BOL,Population (Total),SP.POP.TOTL,3353125,3428270,3505427,3584782,3666584,3751047,3838156,3927961,4020815,4117153,4217248,4321324,4429194,4540197,4653409,4768177,4884284,5001971,5121608,5243771,5368901,5497112,5628347,5762673,5900127,6040757,6184440,6331219,6481463,6635658,6794046,6956736,7123294,7292745,7463773,7635362,7806953,7978521,8150214,8322408,8495271,8669066,8843350,9016787,9187610,9354709,9517395,9676456,9834098,9993406,10156601,10324445,10496285, - , - , - , - , - , - , - " & @CRLF & _ "Brazil,BRA,Population (Total),SP.POP.TOTL,72775883,74988037,77286629,79643017,82017016,84379369,86721875,89052356,91377490,93709914,96060361,98427874,100812672,103228641,105693434,108219657,110808302,113455308,116160978,118924135,121740438,124610790,127525420,130455659,133364277,136223043,139023394,141767626,144452622,147078659,149648341,152153539,154597985,157011131,159432909,161890816,164392423,166925457,169472347,172006362,174504898,176968205,179393768,181752951,184010283,186142403,188134315,189996976,191765567,193490922,195210154,196935134,198656019, - , - , - , - , - , - , - " & @CRLF & _ "Congo, Rep.,COG,Population (Total),SP.POP.TOTL,1013581,1039958,1067589,1096468,1126573,1157905,1190424,1224187,1259394,1296306,1335090,1375876,1418556,1462767,1508000,1553903,1600295,1647320,1695348,1744922,1796412,1849970,1905411,1962375,2020333,2078914,2138090,2198025,2258785,2320488,2383283,2447020,2511819,2578424,2647817,2720633,2797572,2878333,2961357,3044444,3126204,3205636,3283719,3363418,3448868,3542867,3646653,3758858,3876475,3995146,4111715,4225359,4337051, - , - , - , - , - , - , - " & @CRLF & _ "Egypt, Arab Rep.,EGY,Population (Total),SP.POP.TOTL,27997745,28785879,29590639,30409962,31241836,32083955,32937066,33798820,34660399,35510567,36342268,37152209,37945429,38733784,39533995,40359038,41212513,42093668,43005773,43951351,44931971,45945655,46991385,48071851,49190419,50346551,51545011,52776850,54011214,55207254,56336614,57387589,58370712,59307778,60231864,61168397,62123592,63094069,64084443,65097777,66136590,67204189,68302914,69432477,70591288,71777678,72990754,74229577,75491922,76775023,78075705,79392466,80721874, - , - , - , - , - , - , - " & @CRLF & _ "Micronesia, Fed. Sts.,FSM,Population (Total),SP.POP.TOTL,44539,45956,47387,48875,50483,52238,54201,56324,58404,60167,61433,62107,62298,62289,62477,63146,64386,66110,68221,70550,72967,75462,78057,80678,83242,85689,87948,90024,92020,94091,96331,98800,101412,103937,106057,107556,108342,108506,108236,107808,107430,107170,106983,106816,106575,106198,105686,105097,104498,103983,103619,103424,103395, - , - , - , - , - , - , - " & @CRLF & _ "Bahamas, The,BHS,Population (Total),SP.POP.TOTL,109526,115108,121083,127331,133697,140049,146364,152607,158629,164250,169356,173867,177844,181489,185097,188882,192905,197118,201511,206038,210660,215404,220274,225184,230014,234684,239135,243397,247585,251863,256338,261102,266097,271105,275820,280050,283678,286845,289926,293442,297759,303005,309039,315624,322400,329088,335622,342049,348340,354492,360498,366331,371960, - , - , - , - , - , - , - " & @CRLF & _ "Macao SAR, China,MAC,Population (Total),SP.POP.TOTL,171456,175135,181025,188703,197523,206910,216873,227258,237129,245310,250997,253881,254282,252845,250550,248213,245915,243729,242458,243073,246236,252258,260921,271674,283672,296222,309226,322655,335952,348467,359735,369484,377799,385041,391783,398459,405231,412031,418810,425448,431907,438080,444150,450711,458542,468149,479808,493206,507528,521617,534626,546278,556783, - , - , - , - , - , - , - " & @CRLF & _ "Macedonia, FYR,MKD,Population (Total),SP.POP.TOTL,1471139,1491446,1512404,1533999,1556150,1578730,1601987,1625829,1649396,1671533,1691507,1708662,1723445,1737547,1753342,1772405,1795556,1821920,1849320,1874648,1895727,1911496,1922729,1931280,1939913,1950487,1964188,1980064,1995338,2006063,2009710,2004813,1993080,1978999,1968851,1967013,1975207,1991687,2013117,2034487,2052129,2065098,2074441,2080866,2085728,2090044,2093801,2096620,2098769,2100558,2102216,2103890,2105575, - , - , - , - , - , - , - " & @CRLF & _ "Korea, Dem. Rep.,PRK,Population (Total),SP.POP.TOTL,11424179,11665593,11871721,12065471,12282423,12547526,12864685,13221828,13608614,14009171,14410403,14812366,15214618,15603005,15960131,16274744,16539033,16758831,16953627,17151326,17372172,17623339,17899241,18191886,18488002,18778106,19058994,19334557,19610518,19895397,20194361,20510215,20838090,21166238,21478552,21763678,22016518,22240833,22444993,22641754,22840225,23043449,23248059,23449180,23639303,23813333,23969917,24111989,24243894,24371865,24500520,24631291,24763188, - , - , - , - , - , - , - " & @CRLF & _ "Gambia, The,GMB,Population (Total),SP.POP.TOTL,367929,376736,383525,389070,394552,400865,408182,416342,425509,435800,447283,460193,474538,489860,505512,521070,536409,551823,567828,585155,604371,625413,648202,673230,701097,732092,766598,804134,843060,881146,916811,949479,979666,1008242,1036580,1065746,1095930,1126986,1159271,1193143,1228863,1266691,1306667,1348548,1391934,1436549,1482324,1529406,1577984,1628332,1680640,1734966,1791225, - , - , - , - , - , - , - " & @CRLF & _ "Hong Kong SAR, China,HKG,Population (Total),SP.POP.TOTL,3075605,3168100,3305200,3420900,3504600,3597900,3629900,3722800,3802700,3863900,3959000,4045300,4123600,4241600,4334200,4461600,4518000,4583700,4667500,4929700,5063100,5183400,5264500,5345100,5397900,5456200,5524600,5590500,5627600,5686200,5704500,5752000,5800500,5901000,6035400,6156100,6435500,6489300,6543700,6606500,6665000,6714300,6744100,6730800,6783500,6813200,6857100,6916300,6957800,6972800,7024200,7071600,7154600, - , - , - , - , - , - , - " & @CRLF & _ "Venezuela, RB,VEN,Population (Total),SP.POP.TOTL,7580281,7872644,8172322,8477485,8785731,9095742,9406598,9719951,10040248,10373554,10724328,11093065,11478612,11881567,12302193,12739894,13196169,13669054,14150223,14628595,15096432,15549525,15990376,16426198,16867806,17322754,17793283,18275997,18766017,19256060,19740786,20218813,20691641,21160262,21626607,22092144,22556838,23020184,23482700,23945002,24407553,24870441,25333622,25797219,26261326,26725897,27190882,27655937,28120312,28583040,29043283,29500625,29954782, - , - , - , - , - , - , - " & @CRLF & _ "Yemen, Rep.,YEM,Population (Total),SP.POP.TOTL,5099785,5184477,5276093,5372934,5472775,5573959,5677339,5783454,5890204,5994901,6096574,6193897,6290197,6394922,6520690,6676714,6866630,7088585,7339452,7613672,7906977,8220933,8557021,8910830,9276622,9651313,10028064,10409987,10815614,11270427,11790249,12384543,13040955,13726827,14396720,15018201,15578640,16088019,16564235,17035531,17522537,18029989,18551068,19081306,19612696,20139661,20661714,21182162,21703571,22229625,22763008,23304206,23852409, - , - , - , - , - , - , - " & @CRLF & _ "Congo, Dem. Rep.,COD,Population (Total),SP.POP.TOTL,15248246,15637715,16041247,16461914,16903899,17369859,17861860,18378189,18913177,19458874,20009902,20563258,21121467,21691346,22282713,22902275,23554958,24238011,24941431,25650884,26357407,27060353,27767775,28490510,29243529,30039873,30871855,31740965,32679158,33727905,34910591,36253025,37731020,39257294,40711816,42012524,43122601,44078397,44960941,45889100,46949244,48167045,49516960,50972323,52487293,54028003,55590838,57187942,58819038,60486276,62191161,63931512,65705093, - , - , - , - , - , - , - " & @CRLF & _ "" Local $sSubst = ""\1"\2" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm