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

/
/
gm

Test String

Code Generator

Generated Code

use strict; my $str = '<p><span class=\'label\'>Adapter_Classes</span>: <div class=\'metadata list\' id=\'adapter_classes\'><ul> <li>FanFictionNetSiteAdapter</li> </ul></div><p> <p><span class=\'label\'>Author</span>: <div class=\'metadata list\' id=\'author\'><ul> <li>Ms Katonic</li> </ul></div><p> <p><span class=\'label\'>Authorhtml</span>: <div class=\'metadata\' id=\'authorHTML\'><a class=\'authorlink\' href=\'https://www.fanfiction.net/u/27687/Ms-Katonic\'>Ms Katonic</a></div><p> <p><span class=\'label\'>Author ID</span>: <div class=\'metadata list\' id=\'authorId\'><ul> <li>27687</li> </ul></div><p> <p><span class=\'label\'>Author URL</span>: <div class=\'metadata list\' id=\'authorUrl\'><ul> <li>https://www.fanfiction.net/u/27687/Ms-Katonic</li> </ul></div><p> <p><span class=\'label\'>Category</span>: <div class=\'metadata list\' id=\'category\'><ul> <li>Elder Scroll series</li> </ul></div><p> <p><span class=\'label\'>Characters</span>: <div class=\'metadata list\' id=\'characters\'><ul> <li>Elisif</li> <li>Argis the Bulwark</li> <li>Madanach</li> <li>Ulfric Stormcloak</li> </ul></div><p> <p><span class=\'label\'>Packaged</span>: <div class=\'metadata datetime\' id=\'dateCreated\'>2020-11-26T00:15:59.499793</div><p> <p><span class=\'label\'>Published</span>: <div class=\'metadata datetime\' id=\'datePublished\'>2013-09-28T12:26:48</div><p> <p><span class=\'label\'>Updated</span>: <div class=\'metadata datetime\' id=\'dateUpdated\'>2015-05-05T18:23:45</div><p> <p><span class=\'label\'>Summary</span>: <div class=\'metadata\' id=\'description\'>Dragons may signify the world\'s end but as far as Elisif\'s concerned, her world ended well before that when Ulfric Stormcloak murdered her husband. So it is that no one\'s more surprised than her when a dragon attack on Solitude reveals that there\'s more to the High Queen in waiting than anyone</div><p> <p><span class=\'label\'>Extra Tags</span>: <div class=\'metadata list\' id=\'extratags\'><ul> <li>FanFiction</li> </ul></div><p> <p><span class=\'label\'>Favs</span>: <div class=\'metadata\' id=\'favs\'>343</div><p> <p><span class=\'label\'>Follows</span>: <div class=\'metadata\' id=\'follows\'>245</div><p> <p><span class=\'label\'>File Extension</span>: <div class=\'metadata\' id=\'formatext\'>.epub</div><p> <p><span class=\'label\'>File Format</span>: <div class=\'metadata\' id=\'formatname\'>epub</div><p> <p><span class=\'label\'>Genre</span>: <div class=\'metadata list\' id=\'genre\'><ul> <li>Adventure</li> <li>Drama</li> </ul></div><p> <p><span class=\'label\'>Langcode</span>: <div class=\'metadata\' id=\'langcode\'>en</div><p> <p><span class=\'label\'>Language</span>: <div class=\'metadata\' id=\'language\'>English</div><p> <p><span class=\'label\'>Lastupdate</span>: <div class=\'metadata list\' id=\'lastupdate\'><ul> <li>Last Update Year/Month: 2015/05</li> <li>Last Update: 2015/05/05</li> </ul></div><p> <p><span class=\'label\'>Chapters</span>: <div class=\'metadata int\' id=\'numChapters\'>50</div><p> <p><span class=\'label\'>Words</span>: <div class=\'metadata\' id=\'numWords\'>383,344</div><p> <p><span class=\'label\'>Python_Version</span>: <div class=\'metadata\' id=\'python_version\'>3.8.5 (default, Aug 26 2020, 22:00:02) [MSC v.1927 64 bit (AMD64)]</div><p> <p><span class=\'label\'>Rating</span>: <div class=\'metadata\' id=\'rating\'>M</div><p> <p><span class=\'label\'>Reviews</span>: <div class=\'metadata\' id=\'reviews\'>203</div><p> <p><span class=\'label\'>Story URL Section</span>: <div class=\'metadata\' id=\'sectionUrl\'>https://www.fanfiction.net/s/9721808/1/</div><p> <p><span class=\'label\'>Publisher</span>: <div class=\'metadata\' id=\'site\'>www.fanfiction.net</div><p> <p><span class=\'label\'>Site Abbrev</span>: <div class=\'metadata\' id=\'siteabbrev\'>ffnet</div><p> <p><span class=\'label\'>Status</span>: <div class=\'metadata\' id=\'status\'>Completed</div><p> <p><span class=\'label\'>Story ID</span>: <div class=\'metadata\' id=\'storyId\'>9721808</div><p> <p><span class=\'label\'>Story URL</span>: <div class=\'metadata\' id=\'storyUrl\'>https://www.fanfiction.net/s/9721808/1/</div><p> <p><span class=\'label\'>Title</span>: <div class=\'metadata\' id=\'title\'>The Wolf Queen Awakens</div><p> <p><span class=\'label\'>Titlehtml</span>: <div class=\'metadata\' id=\'titleHTML\'><a class=\'titlelink\' href=\'https://www.fanfiction.net/s/9721808/1/\'>The Wolf Queen Awakens</a></div><p> <p><span class=\'label\'>Downloader Version</span>: <div class=\'metadata\' id=\'version\'>FanFicFare v3.99.18</div><p>'; my $regex = qr/<p><span class='label'>Rating<\/span>: <div class='metadata' id='rating'>(.*?)<\/div><p>/mp; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html