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
No Match

r"
"
g

Test String

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"x^" test_str = ("unavailable speedometer's garbling Zambia subcontracted fullbacks Belmont mantra's\n" "pizzicatos carotids bitch Hernandez renovate leopard Knuth coarsen\n" "Ramada flu occupies drippings peaces siroccos Bartók upside twiggier configurable perpetuates tapering pint paralyzed\n" "vibraphone stoppered weirdest dispute clergy's getup perusal fork\n" "nighties resurgence chafe\n" "slop's overdosed clewing lidded superstition regale swisher jaundiced multiplexors Indiana's Marquis fisher's\n" "weekend's millimeter Khalid's knowingly\n" "Clyde diuretic raggedness's Socratic initialization pluralized swilling louver's Caedmon's outreach's return regression shortened azures ultra's point bumping\n" "sidesaddle's waxen Brussels wrested currant's scented Ariadne whammy hypertext's patrimony's Sicilians why indivisibility eluded scrounged impaneled grimaced friction's\n" "infringing Sardinia's Dyer Seder's\n" "amaze's\n" "beeping potters cauldron's carnival's parricides sellouts roomiest Buick's bingeing gently procure Darin's inheritor Doonesbury's baldest tomfoolery's democratizes donates wage's\n" "pencil obscure Opel's cymbal's loggerhead's cubed inessential's enrapturing gypsy\n" "Velveeta capitalists garnets Waikiki shticks stoat's shred's anneals columned river's continuum preferring beloveds Junes Flintstones\n\n" "Buick's epaulette's legalized impecuniousness Apollonian esoterically attack fry's Hal some sweltered enduing astrological Sandy marble's chameleon reapportionment's\n" "jeopardize Vaughn's antibodies carefully manifestation speakeasy's bookseller's\n" "Freetown purplest japans Ruth audit Carr deceit schticks subservience kidnapper agrarians committal cashmere's Lanny's despondency stigmatizes Guiyang\n" "mudslides grayness's Scotsmen recordings imparts windmilling cordite's worthlessness's tone\n" "object uncommonest truism barbecued psychobabble's Lyndon's uncritical longevity shamefulness's overborne ulceration's\n" "crud underweight's paginated phalli demonstratives indices deconstruction upright beetles stalemated Mediterranean surtax's sameness's pinafore piety purism truncation\n" "satire jog Ward sullenness's counterclockwise portcullis's polyphony's aeration's injustices\n" "geode's pouch's\n" "charbroils crinoline advantaging nautilus's tangibility's progressing Evian copper sicken sublimates hoards\n" "linseed's pheromone's approves clamor Henderson's tinkles demerit agonized Alec defrosting hotel\n" "surveyors rib's African ghostwriting overrule sequoias Morales's whacks gantry alienable peddled\n" "boardinghouses touts Slackware vindications rose's\n" "morals acquaintances overreact cerebella Eu's blessedness's master palimony's perming mammalian's homophobic beefing fours sermonizes\n" "Japura propagandists dulness momentous beer's cadaver's Kochab yawning Francoise's\n" "dose's spike's plasterboard rendezvouses bitched nun's doodle hospitalize unwieldiness's torturer\n" "abettor's predominantly tracker coagulation's shingle demoted lousiness\n" "Trina poinsettias Wichita bellhops ammo's divinity's necking overcoming\n" "physics backhoes rotary skylarks establishments adversity flood's\n" "Bowery's tussled hoppers arachnid's Wilfred Gatling cranium ids salmonella\n" "abdomens codeine's Urumqi mythology Macedonia's Kenmore's\n" "trounces curses Comte faulting prefixes newel smugglers bawl's methodologies Max\n" "tobogganing Olenek's adjudge loth\n" "floaters update silence jiggers revolutionist sepulcher Formica's searchingly Cartesian Maya's halved hydrolysis McCullough's Zsigmondy badmouthed danced revolutionary slum's lanyards\n" "repercussion's wrongfulness's earth's neonate Carmelo's\n" "struggled heliports weathercock's appeasing pinched relegation weaned nappy\n" "manganese deciduous ganged Mahayanist herbs individualizing repartee Albert aerators evolution monicker's electrifies Conner drooling Margret kibitzer excitation's Merriam's\n" "misfortune ell determinations forever's trumpeting dreadfully voyeur's Markov noiselessly catechise cleaners muffler's gentleness's condense scholarship's Sang\n" "Jeeves's Chappaquiddick's deodorants Tonia fixture preparations newsletter Nicola Stanton algorithms\n" "honchos outspreading Kutuzov divulged\n" "partition zinging Burnett cadge scrape's Poiret sulfured simplicity's inpatient's cottonwood sublease sublimate staled\n" "mimicking disbarred shopping forgets jurist adulate bakery's pinkish atlases hatched encouraging flatware's talkers instrumentation negotiate refresher\n" "Novosibirsk oblivious payment's widens\n" "impoverishment's beehive's domination's etymologists virology Macon\n" "humbugs inlaying truncheons downstream aesthetically substructure's fumigate Nannie afflicted Jr mimics pipsqueaks eBay's solid ague's\n" "company herdsman misstates authorship pugnacity unlock flavor's Sn's longhand's trespass underscore Andean\n") matches = re.finditer(regex, test_str) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # 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