Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"\",]" test_str = "[[\"USA\",1,2],[\"Canada\",0],[\"Mexico\",0,4,3],[\"Guatemala\",2,4,5,6],[\"Belize\",2,3],[\"El Salvador\",3,6],[\"Honduras\",3,5,7],[\"Nicaragua\",6,8],[\"San Jose\",7,9],[\"Panama\",8,10],[\"Columbia\",11,15,17,16],[\"Venezuela\",10,15,12],[\"Guyana\",11,15,13],[\"Suriname\",12,15,14],[\"French Guiana\",13,15],[\"Brazil\",10,11,12,13,14,17,18,20,21,22],[\"Ecuador\",10,17],[\"Peru\",16,10,15,18,19],[\"Bolivia\",17,15,20,21,19],[\"Chile\",17,18,21],[\"Paraguay\",18,15,21],[\"Argentina\",19,18,20,15,22],[\"Uruguay\",21,15],[\"The Bahamas\",],[\"Cuba\",],[\"Jamaica\",],[\"Haiti\",27],[\"Dominican Republic\",26],[\"Puerto Rico\",],[\"Saint Kitts and Nevis\",],[\"Montserrat\",],[\"Guadeloupe\",],[\"Dominica\",],[\"Martinique\",],[\"Saint Vincent\",],[\"Barbados\",],[\"Trinidad and Tobago\",],[\"Greenland\",],[\"Azores\",],[\"Falkland Islands\",],[\"South Georgia\",],[\"Cape Verde\",],[\"Madeira Island\",],[\"Canary Islands\",],[\"Faroe Islands\",],[\"Republic of Ireland\",46],[\"United Kingdom\",45],[\"Svalbard\",],[\"Norway\",49,50,51],[\"Sweden\",48,50],[\"Finland\",49,48,51],[\"Russia\",48,50,53,54,56,62,84,87,88,89,93,90,91],[\"Denmark\",57],[\"Estonia\",51,54],[\"Latvia\",53,51,56,55],[\"Lithuania\",54,56,61],[\"Belarus\",55,54,51,62,61],[\"Germany\",60,59,58,52,61,63,68,69,71,70],[\"Netherlands\",57,59],[\"Belgium\",70,58,57,60],[\"Luxembourg\",70,59,57],[\"Poland\",57,55,56,62,64,63],[\"Ukraine\",64,61,56,51,66,65,67],[\"Czech Republic\",57,61,64,68],[\"Slovakia\",68,63,61,62,67],[\"Moldova\",62,66],[\"Romania\",67,62,65,76,75],[\"Hungary\",68,64,62,66,75,73,72],[\"Austria\",69,57,63,64,67,72,80,71],[\"Liechtenstein\",71,57,68],[\"France\",59,60,57,71,80,81],[\"Switzerland\",70,57,69,68,80],[\"Slovenia\",80,68,67,73],[\"Croatia\",72,67,75,74],[\"Bosnia and Herzegovina\",73,75,77],[\"Serbia\",74,73,67,66,76,79,78,77],[\"Bulgaria\",75,66,84,83,79],[\"Montenegro\",74,75,78],[\"Albania\",77,75,79,83],[\"Macedonia\",78,75,76,83],[\"Italy\",70,71,68,72],[\"Spain\",82,70],[\"Portugal\",81],[\"Greece\",78,79,76,84],[\"Turkey\",83,51,87,88,97,98,99],[\"Malta\",],[\"Cyprus\",],[\"Armenia\",84,51,88,97],[\"Azerbaijan\",84,87,51,97],[\"Kazakhstan\",51,93,94,96],[\"Mongolia\",93,51],[\"North Korea\",93,51,92],[\"South Korea\",91],[\"China\",95,94,89,51,90,91,120,119,117,111,113,112,110],[\"Uzbekistan\",89,93,95,96],[\"Afghanistan\",97,96,94,93,110,109],[\"Turkmenistan\",89,94,95,97],[\"Iran\",98,84,88,87,96,95,109],[\"Iraq\",102,99,84,97,104,103],[\"Syria\",100,84,98,102,101],[\"Lebanon\",101,99],[\"Israel\",145,100,99,102],[\"Jordan\",101,99,98,103],[\"Saudi Arabia\",102,98,104,105,106,107,108],[\"Kuwait\",98,103],[\"Qatar\",103],[\"United Arab Emirates\",103,107],[\"Oman\",103,106,108],[\"Yemen\",103,107],[\"Pakistan\",97,95,110,111],[\"Kashmir\",109,95,93,111],[\"India\",109,110,112,113,117,114],[\"Nepal\",111,93],[\"Bhutan\",111,93],[\"Bangladesh\",111,117],[\"Sri Lanka\",],[\"Adaman and Nicobar Islands\",],[\"Myanmar\",114,111,93,119,118],[\"Thailand\",117,119,121,122],[\"Laos\",117,93,120,121,118],[\"Vietnam\",119,93,121],[\"Cambodia\",118,119,120],[\"Malaysia\",118,123,125],[\"Brunei\",122],[\"Phillipines\",],[\"Indonesia\",122,126,127],[\"Papua New Guinea\",125],[\"Australia\",],[\"Tasmania\",],[\"Japan\",],[\"Guam\",],[\"Solomon Islands\",],[\"Vanuatu\",],[\"Fiji\",],[\"New Caledonia\",],[\"New Zealand\",],[\"Kerguelen Island\",],[\"Heard Island\",],[\"Mauritius\",],[\"Reunion\",],[\"Mayotte\",],[\"Comoros\",],[\"Madagascar\",],[\"Sao Tome\",],[\"Bioko\",],[\"Egypt\",146,101,167],[\"Libya\",148,147,145,167,166,164],[\"Tunisia\",148,146],[\"Algeria\",150,149,147,146,164,159,151],[\"Morocco\",150,148],[\"Western Sahara\",149,148,151],[\"Mauritania\",150,148,159,152],[\"Senegal\",153,151,159,155,154],[\"The Gambia\",152],[\"Guinea-Bissau\",152,155],[\"Guinea\",154,152,159,158,157,156],[\"Sierra Leone\",155,157],[\"Liberia\",156,155,158],[\"Cote D'Ivoire\",157,155,159,160,161],[\"Mali\",152,151,148,164,160,158,155],[\"Burkina Faso\",159,164,163,162,161,158],[\"Ghana\",158,160,162],[\"Togo\",161,160],[\"Benin\",162,160,164,165],[\"Niger\",160,159,148,146,166,165,163],[\"Nigeria\",163,164,166,176],[\"Chad\",164,146,167,175,176,165],[\"Sudan\",166,146,145,168,170,172,173,174,175],[\"Eritrea\",167,169,170],[\"Djibouti\",170,168,171],[\"Ethiopia\",167,168,169,171,172],[\"Somalia\",172,170,169],[\"Kenya\",173,167,170,171,182],[\"Uganda\",174,167,172,182,180],[\"Democratic Republic of the Congo\",183,179,175,167,173,180,181,185,184],[\"Central African Republic\",176,166,167,174,179],[\"Cameroon\",165,166,175,179,178,177],[\"Equatorial Guinea\",176,178],[\"Gabon\",177,176,179],[\"Congo\",178,176,175,174,183],[\"Rwanda\",174,173,182,181],[\"Burundi\",174,180,182],[\"Tanzania\",181,180,173,172,187,186,185],[\"Cabinda\",179,174],[\"Angola\",174,185,190],[\"Zambia\",184,174,182,186,187,188,189,190],[\"Malawi\",185,182,187],[\"Mozambique\",188,185,186,182,191,192],[\"Zimbabwe\",190,185,187,191,189],[\"Botswana\",190,185,188,191],[\"Namibia\",184,185,188,189,191],[\"South Africa\",190,189,188,187,192,193],[\"Swaziland\",191,187],[\"Lesotho\",191]]" subst = "\"]" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 0) if result: print (result) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html