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

/
/
gm

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"<\/p><p>.*>(.+?)<.*[:-] (.*)" test_str = ("</p><p><b><a href=\"/index.php/AGS\" title=\"AGS\">AGS</a></b>: Amazon Global Store\n" "</p><p><b><a href=\"/index.php?title=APPH&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"APPH (page does not exist)\">APPH</a></b>: Actual Pick Rate\n" "</p><p><b>APV</b>: Amazon Prime Video\n" "</p><p><b><a href=\"/index.php?title=ASK_ID&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"ASK ID (page does not exist)\">ASK ID</a></b>: Alexa Skills Kit International Data\n" "</p><p><b><a href=\"/index.php/AWS\" title=\"AWS\">AWS</a></b>: Advertiser Web Services\n" "</p><p><b><a href=\"/index.php/CBP\" title=\"CBP\">CBP</a></b>: Cross Border Pricing\n" "</p><p><b><a href=\"/index.php/CDF\" title=\"CDF\">CDF</a></b>: Cumulative Distribution Function\n" "</p><p><b><a href=\"/index.php?title=CVSD&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"CVSD (page does not exist)\">CVSD</a></b>: Convenience Store Delivery\n" "</p><p><b><a href=\"/index.php/CWGR\" title=\"CWGR\">CWGR</a></b>: Compound Weekly Growth Rate\n" "</p><p><b>DEXTER</b>: Delivery Execution Tracking Evaluation and Reconciliation\n" "</p><p><b><a href=\"/index.php?title=DMI&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"DMI (page does not exist)\">DMI</a></b>: Desktop Management Interface\n" "</p><p><b>DNB</b>: Digital Native Business (AWS)\n" "</p><p><b>eCPDPV</b>: effective Cost Per Detail Page View\n" "</p><p><b>EOR</b>: Exporter of Record (see also IOR)\n" "</p><p><b>FAST</b>: Flexible Accelerated Recruiting Team (Consumer Talent)\n" "</p><p><b>FEC</b>: FC execution cluster/system\n" "</p><p><a href=\"https://w.amazon.com/index.php/TranslationTeam\" class=\"external text\" rel=\"nofollow\"><b>FL</b></a>: Freelance Translation Specialist\n" "</p><p><b><a href=\"/index.php?title=FMM&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"FMM (page does not exist)\">FMM</a></b>: Field Marketing Manager (AWS)\n" "</p><p><b>FQ</b>: Feature Question (ORR)\n" "</p><p><b><a href=\"/index.php/FRA3\" title=\"FRA3\">FRA3</a></b>: Second FC, Bad Hersfeld\n" "</p><p><b>FRT</b>: First Response Time\n" "</p><p><b>FSSS</b>: Free Super Saver Shipping\n" "</p><p><b>G/NG</b>: Go/No Go\n" "</p><p><b><a href=\"/index.php?title=GOE&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"GOE (page does not exist)\">GOE</a></b>: Global Optimization Engine\n" "</p><p><a href=\"https://w.amazon.com/index.php/Ingenii\" class=\"external text\" rel=\"nofollow\"><b>INGENII</b></a>: Amazon's Career's growth plan tool\n" "</p><p><b>IN</b>: India Marketplace\n" "</p><p><b><a href=\"/index.php/Ion\" title=\"Ion\">ION</a></b>: Inter-operable Object Notation\n" "</p><p><b>IOR</b>: Importer of Record (see also EOR)\n" "</p><p><b><a href=\"/index.php?title=LCPO&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"LCPO (page does not exist)\">LCPO</a></b>: Low Confidence Purchase Order\n" "</p><p><b>LRR</b>: Launch Readiness Review\n" "</p><p><b><a href=\"/index.php?title=MQL&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"MQL (page does not exist)\">MQL</a></b>: Marketing Qualified Lead (AWS)\n" "</p><p><b><a href=\"/index.php/MUC3\" title=\"MUC3\">MUC3</a></b>: FC, Graben\n" "</p><p><b>OLVCS</b>: Offer Level VAT Calculation Services\n" "</p><p><b><a href=\"/index.php?title=P2S&amp;action=edit&amp;redlink=1\" class=\"new\" title=\"P2S (page does not exist)\">P2S</a></b>: Propensity to Spend (AWS)\n" "</p><p><a href=\"https://w.amazon.com/index.php/B2B/ProfessionalLicensing\" class=\"external text\" rel=\"nofollow\"><b>PLP</b></a>: Professional Licensing Program\n" "</p><p><b><a href=\"/index.php/RAP\" title=\"RAP\">RAP</a></b>: Recruiter Academy Program (Consumer Talent)\n" "</p><p><b><a href=\"/index.php/RHEL\" title=\"RHEL\">RHEL</a></b>: Red Hat Enterprise Linux\n" "</p><p><b><a href=\"/index.php/RFV\" title=\"RFV\">RFV</a></b>: Resolving For Visibility\n" "</p><p><b><a href=\"/index.php/RHMD\" title=\"RHMD\">RHMD</a></b>: Recruiter How's My Driving\n" "</p><p><b><a href=\"/index.php/SLCS\" title=\"SLCS\">SLCS</a></b>: <a href=\"/index.php/SourcingLandedCostService\" title=\"SourcingLandedCostService\">Sourcing Landed Cost Service</a> (See also <b><a href=\"/index.php/LandedCost\" title=\"LandedCost\">Landed Cost</a></b>)\n" "</p><p><b><a href=\"/index.php/SRL\" title=\"SRL\">SRL</a></b>: Start Reading Location, a feature on Kindle that opens ebooks to the title page, for KiM titles it's set to the cover page so the customer can view the illustrated motion\n" "</p><p><b><a href=\"/index.php/SSX\" title=\"SSX\">SSX</a></b>: Shared Shopping Experience\n" "</p><p><b><a href=\"/index.php/SQL\" title=\"SQL\">SQL</a></b>: Sales Qualified Lead (AWS)\n" "</p><p><b><a href=\"https://w.amazon.com/index.php/TranslationTeam\" class=\"external text\" rel=\"nofollow\">TS</a></b>: Translation Specialist\n" "</p><p><b><a href=\"/index.php/VAS\" title=\"VAS\" class=\"mw-redirect\">VAS</a></b>: Value Added Services <b><a href=\"https://w.amazon.com/bin/view/ValueAddedServices/Glossary/\" class=\"external text\" rel=\"nofollow\">(VAS Specific Acronyms)</a></b>\n" "</p><p><b><a href=\"/index.php/VF\" title=\"VF\">VF</a></b>: Vinnige Fanie") subst = "$1 - $2" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 0, re.MULTILINE) 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