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"
"
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"(?s).*(<p><span class='label'>Rating<\/span>: <div class='metadata' id='rating'>(.*?)<\/div><p>).*" test_str = ("<p><span class='label'>Adapter_Classes</span>: <div class='metadata list' id='adapter_classes'><ul>\n" "<li>ArchiveOfOurOwnOrgAdapter</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>AO3 Categories</span>: <div class='metadata list' id='ao3categories'><ul>\n" "<li>Gen</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Author</span>: <div class='metadata list' id='author'><ul>\n" "<li>ofwyrmsandguns</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Authorhtml</span>: <div class='metadata' id='authorHTML'><a class='authorlink' href='https://archiveofourown.org/users/ofwyrmsandguns/pseuds/ofwyrmsandguns'>ofwyrmsandguns</a></div><p>\n\n" "<p><span class='label'>Author ID</span>: <div class='metadata list' id='authorId'><ul>\n" "<li>ofwyrmsandguns</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Author URL</span>: <div class='metadata list' id='authorUrl'><ul>\n" "<li>https://archiveofourown.org/users/ofwyrmsandguns/pseuds/ofwyrmsandguns</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Bookmarks</span>: <div class='metadata' id='bookmarks'>1</div><p>\n\n" "<p><span class='label'>Byline</span>: <div class='metadata' id='byline'>ofwyrmsandguns</div><p>\n\n" "<p><span class='label'>Chapters/Total Chapters</span>: <div class='metadata' id='chapterslashtotal'>5/?</div><p>\n\n" "<p><span class='label'>Characters</span>: <div class='metadata list' id='characters'><ul>\n" "<li>Talen-Jei (Elder Scrolls)</li>\n" "<li>Original Characters</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Cover_Image</span>: <div class='metadata' id='cover_image'>old</div><p>\n\n" "<p><span class='label'>Packaged</span>: <div class='metadata datetime' id='dateCreated'>2023-02-14T16:45:24.226001</div><p>\n\n" "<p><span class='label'>Published</span>: <div class='metadata datetime' id='datePublished'>2023-01-25T00:00:00</div><p>\n\n" "<p><span class='label'>Updated</span>: <div class='metadata datetime' id='dateUpdated'>2023-02-14T00:00:00</div><p>\n\n" "<p><span class='label'>Summary</span>: <div class='metadata' id='description'><div class=\"userstuff\">\n" " <p>In 4E 201, Talen-Jei, a bartender in Riften, somehow sells a drink that references on ex-black hand from the Dark Brotherhood. Wherever this drink got it's name, it can't be a coincidence that the drink with nightshade has the link to the Dark Brotherhood. Where did he get the name from? What was he doing in Gideon's bar, other than making drinks?</p><p>(AKA: A backstory for Talen-Jei before he came to Riften, and his work as a Shadowscale before going renegade, and the order dissolving.)</p>\n" " </div></div><p>\n\n" "<p><span class='label'>Extra Tags</span>: <div class='metadata list' id='extratags'><ul>\n" "<li>FanFiction</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Fandoms</span>: <div class='metadata list' id='fandoms'><ul>\n" "<li>Elder Scrolls V: Skyrim</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>File Extension</span>: <div class='metadata' id='formatext'>.epub</div><p>\n\n" "<p><span class='label'>File Format</span>: <div class='metadata' id='formatname'>epub</div><p>\n\n" "<p><span class='label'>Freeform Tags</span>: <div class='metadata list' id='freeformtags'><ul>\n" "<li>Shadowscales</li>\n" "<li>Original Character(s)</li>\n" "<li>character backstory</li>\n" "<li>Implied/Referenced Alcohol Abuse/Alcoholism</li>\n" "<li>Alcohol</li>\n" "<li>Minor Character Death</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Hits</span>: <div class='metadata' id='hits'>23</div><p>\n\n" "<p><span class='label'>Langcode</span>: <div class='metadata' id='langcode'>en</div><p>\n\n" "<p><span class='label'>Language</span>: <div class='metadata' id='language'>English</div><p>\n\n" "<p><span class='label'>Lastupdate</span>: <div class='metadata list' id='lastupdate'><ul>\n" "<li>Last Update Year/Month: 2023/02</li>\n" "<li>Last Update: 2023/02/14</li>\n" "</ul></div><p>\n\n" "<p><span class='label'>Chapters</span>: <div class='metadata int' id='numChapters'>5</div><p>\n\n" "<p><span class='label'>Words</span>: <div class='metadata' id='numWords'>17789</div><p>\n\n" "<p><span class='label'>Python_Version</span>: <div class='metadata' id='python_version'>3.10.1 (main, Dec 23 2021, 12:15:59) [MSC v.1929 64 bit (AMD64)]</div><p>\n\n" "<p><span class='label'>Rating</span>: <div class='metadata' id='rating'>Teen And Up Audiences</div><p>\n\n" "<p><span class='label'>Story URL Section</span>: <div class='metadata' id='sectionUrl'>https://archiveofourown.org/works/44538691</div><p>\n\n" "<p><span class='label'>Series</span>: <div class='metadata' id='series00HTML'></div><p>\n\n" "<p><span class='label'>Additional Series</span>: <div class='metadata' id='series01HTML'></div><p>\n\n" "<p><span class='label'>Additional Series</span>: <div class='metadata' id='series02HTML'></div><p>\n\n" "<p><span class='label'>Additional Series</span>: <div class='metadata' id='series03HTML'></div><p>\n\n" "<p><span class='label'>Publisher</span>: <div class='metadata' id='site'>archiveofourown.org</div><p>\n\n" "<p><span class='label'>Site Abbrev</span>: <div class='metadata' id='siteabbrev'>ao3</div><p>\n\n" "<p><span class='label'>Status</span>: <div class='metadata' id='status'>In-Progress</div><p>\n\n" "<p><span class='label'>Story ID</span>: <div class='metadata' id='storyId'>44538691</div><p>\n\n" "<p><span class='label'>Story URL</span>: <div class='metadata' id='storyUrl'>https://archiveofourown.org/works/44538691</div><p>\n\n" "<p><span class='label'>Title</span>: <div class='metadata' id='title'>The Velvet LaChance</div><p>\n\n" "<p><span class='label'>Titlehtml</span>: <div class='metadata' id='titleHTML'><a class='titlelink' href='https://archiveofourown.org/works/44538691'>The Velvet LaChance</a></div><p>\n\n" "<p><span class='label'>Downloader Version</span>: <div class='metadata' id='version'>FanFicFare v4.20.0</div><p>\n\n" "<p><span class='label'>Warnings</span>: <div class='metadata list' id='warnings'><ul>\n" "<li>Graphic Depictions Of Violence</li>\n" "</ul></div><p>") subst = "\\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