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

/
/
gm

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)(?(DEFINE)" & @CRLF & _ "(?# GUILDS: )" & @CRLF & _ "(?'assassins'(d(octo)?r|professor))" & @CRLF & _ "(?'priests'((?(?=blessed|venerable|holy)(blessed|venerable|holy)( (brother|sister|father|mother))?|(brother|sister|father|mother))|(mostly )?reverend|blessed|beatus|saint|high priest(ess)?|(his|her|it'?s) eminence|minister|outcast))" & @CRLF & _ "(?'thieves'(crafty|crooked|dastardly|dishonest|dodgy|elusive|evasive|furtive|greased|honest|latent|((light|quick)[-]|butter)?finger(ed|s)|quiet|shady|shifty|silent|slick|sly|tricky))" & @CRLF & _ "(?'witches'(?# duplicates: mother, old, mistress, sister)((?# goodie, goody)good(y|ie)|gammer|gra(mma|nny)|(?# mss, mee)m[se]{2}|(?# nanny, nanna)nann[ay]|aunty|biddy|black|mama|wee|wicked|young))" & @CRLF & _ "(?'wizards'(fat|stuffed|overfed|gimlet[-]eyed|robust|bearded|burly|plump|rotund|thin|tiny|mystic|obscure|complex|learned|potent|wise|grumpy|cryptic|dark|scholarly|grey[-]?(haired|beard)|adroit|dire|maven|quantum|savant|unseen|(arch)?(master|mistress|mage)))" & @CRLF & _ "(?# COUNCIL: )" & @CRLF & _ "(?'council_am'(dame|lady|lord|sir)) " & @CRLF & _ "(?'court_positive'the (amazing|civic[-]minded|elegant|eloquent|(helpful|upstanding(?= citizen))( citizen)?|stylish|utterly fluffy|wonderful))" & @CRLF & _ "(?'court_punishment'(appallingly filthy|corpse looter|dull|feebleminded|i (promise i won't do it again|got punished( and all i got was this lousy title)?)|insignificant|lying|malingering|naughty spawn|necrokleptomaniac|offensive|pillock|pointless|repentant|reprobate|shopkeeper murderer|silly spammy git|sitting in the corner|smelly|tantrum thrower|too stupid to live|vagrant|(very ){1,2}sorry|waste of space|whinging))" & @CRLF & _ "(?'council_djb'(?# duplicates: feebleminded, corpse looter, cowardly)(sultana?|(shai|sitt) (al[-](khasa|ri'asa)|ishqu?araya|a'daha)|nawab|qasar|mazrat|effendi|ya'uq|mutasharid|ishqu?araya|naughty spawn|kill stealer|idiotic|offensive|corpse looter|cat hating|heathen|foreign dog|infidel|shopkeeper murderer|destitute|parasitic|hated|cowardly|criminal|felon))" & @CRLF & _ "(?# ACHIEVEMENTS: )" & @CRLF & _ "(?'achievements_thieves'(ruinous|fingers))" & @CRLF & _ "(?'achievements_warriors'(centurion|chef|head(master|mistress)|impaler|pulveriser))" & @CRLF & _ "(?'achievements_witches'(destined|nasty|terrible))" & @CRLF & _ "(?'achievements_fools'pious)" & @CRLF & _ "(?'achievements_wizards'(erratic mechanic|mysterious|arcana))" & @CRLF & _ "(?'achievements_priests'(templar|healer|saintly))" & @CRLF & _ "(?'achievements_assassins'(lethal|venomous))" & @CRLF & _ "(?'achievements_all'(?# axe-master, shieldmaster/mistress, staffmaster/mistress)((sword|shield|staff|axe[-])(master|mistress)|antiquated|archaic|old( (wo)?man)?|bloodthirsty|bruiser|champion|competent|contender|crimewave|crusher|cultured|cutthroat|deckhand|decrepit|diplomatic|duelist|elementalist|energetic|exterminator|festive|filthy|flatulent|fossilized|gifted|golden|knifey|legendary|literate|masterful|medical|miner|multilingual|[nm]urse|mythical|nimble|obsolete|opulent|paranoid|perverse|prehistoric|rock[-]hard|rouge|senile|captain|stormrider|unburiable|unexpected|unlucky|unstoppable|venerable|versatile|virtuoso|wealthy))" & @CRLF & _ "(?'quest_points'(well travelled|persistent))" & @CRLF & _ "(?# MISC: )" & @CRLF & _ "(?'general'm([sx]|rs?|iss))" & @CRLF & _ "(?'genua'(?# m, monsieur, mlle, mademoiselle, mme, madame)m(?=(\Z|$| |me|lle|onsieur|adame|ademoiselle))(me|lle|onsieur|adame|ademoiselle)?)" & @CRLF & _ "(?'ghosts'(lonely|mournful|scary|spooky|wandering))" & @CRLF & _ "(?'musketeers'(cheating|cowardly))" & @CRLF & _ "(?'debaters'(diplomatic|uncreative)))(?#" & @CRLF & _ " TITLE REGEX: " & @CRLF & _ ")^(?<title>(?P>assassins)|(?P>priests)|(?P>thieves)|(?P>witches)|(?P>wizards)|(?P>council_am)|(?P>court_positive)|(?P>court_punishment)|(?P>council_djb)|(?P>achievements_thieves)|(?P>achievements_warriors)|(?P>achievements_witches)|(?P>achievements_fools)|(?P>achievements_wizards)|(?P>achievements_priests)|(?P>achievements_assassins)|(?P>achievements_all)|(?P>quest_points)|(?P>general)|(?P>genua)|(?P>ghosts)|(?P>musketeers)|(?P>debaters))" Local $sString = "GENERAL" & @CRLF & _ "miss" & @CRLF & _ "mr" & @CRLF & _ "mrs" & @CRLF & _ "ms" & @CRLF & _ "mx" & @CRLF & _ "GHOSTS" & @CRLF & _ "lonely" & @CRLF & _ "mournful" & @CRLF & _ "scary" & @CRLF & _ "spooky" & @CRLF & _ "wandering" & @CRLF & _ "MUSKATEERS" & @CRLF & _ "cheating" & @CRLF & _ "cowardly" & @CRLF & _ "ASSASSINS" & @CRLF & _ "doctor" & @CRLF & _ "dr" & @CRLF & _ "professor" & @CRLF & _ "PRIESTS" & @CRLF & _ "brother" & @CRLF & _ "sister" & @CRLF & _ "mostly reverend" & @CRLF & _ "reverend " & @CRLF & _ "blessed " & @CRLF & _ "blessed father " & @CRLF & _ "blessed mother " & @CRLF & _ "blessed brother " & @CRLF & _ "blessed sister " & @CRLF & _ "venerable " & @CRLF & _ "venerable brother " & @CRLF & _ "venerable sister " & @CRLF & _ "venerable father " & @CRLF & _ "venerable mother " & @CRLF & _ "holy " & @CRLF & _ "holy brother " & @CRLF & _ "holy sister " & @CRLF & _ "beatus " & @CRLF & _ "saint " & @CRLF & _ "high priest" & @CRLF & _ "high priestess" & @CRLF & _ "his eminence" & @CRLF & _ "her eminence" & @CRLF & _ "it's eminence" & @CRLF & _ "its eminence" & @CRLF & _ "minister" & @CRLF & _ "THIEVES" & @CRLF & _ "butterfingers" & @CRLF & _ "crafty" & @CRLF & _ "crooked" & @CRLF & _ "dastardly" & @CRLF & _ "dishonest" & @CRLF & _ "dodgy" & @CRLF & _ "elusive" & @CRLF & _ "evasive" & @CRLF & _ "fingers" & @CRLF & _ "furtive" & @CRLF & _ "greased" & @CRLF & _ "honest" & @CRLF & _ "latent" & @CRLF & _ "light-fingered" & @CRLF & _ "quick-fingered" & @CRLF & _ "quiet" & @CRLF & _ "shady" & @CRLF & _ "shifty" & @CRLF & _ "silent" & @CRLF & _ "slick" & @CRLF & _ "sly" & @CRLF & _ "tricky" & @CRLF & _ "WITCHES" & @CRLF & _ "aunty" & @CRLF & _ "biddy" & @CRLF & _ "black" & @CRLF & _ "gammer" & @CRLF & _ "goodie" & @CRLF & _ "goody" & @CRLF & _ "gramma" & @CRLF & _ "granny" & @CRLF & _ "mama" & @CRLF & _ "mistress" & @CRLF & _ "mother" & @CRLF & _ "mss" & @CRLF & _ "nanna" & @CRLF & _ "nanny" & @CRLF & _ "old" & @CRLF & _ "sister" & @CRLF & _ "wee" & @CRLF & _ "wicked" & @CRLF & _ "young" & @CRLF & _ "WIZARDS" & @CRLF & _ "fat" & @CRLF & _ "stuffed" & @CRLF & _ "overfed" & @CRLF & _ "gimlet-eyed" & @CRLF & _ "robust" & @CRLF & _ "bearded" & @CRLF & _ "burly" & @CRLF & _ "plump" & @CRLF & _ "rotund" & @CRLF & _ "thin" & @CRLF & _ "tiny" & @CRLF & _ "mystic" & @CRLF & _ "obscure " & @CRLF & _ "complex" & @CRLF & _ "learned " & @CRLF & _ "potent" & @CRLF & _ "wise" & @CRLF & _ "grumpy " & @CRLF & _ "cryptic" & @CRLF & _ "dark" & @CRLF & _ "scholarly" & @CRLF & _ "grey-haired" & @CRLF & _ "greybeard" & @CRLF & _ "master" & @CRLF & _ "mistress " & @CRLF & _ "adroit" & @CRLF & _ "dire" & @CRLF & _ "maven " & @CRLF & _ "quantum" & @CRLF & _ "savant" & @CRLF & _ "unseen " & @CRLF & _ "archmaster" & @CRLF & _ "mistress" & @CRLF & _ "archmage " & @CRLF & _ "COUNCIL AM" & @CRLF & _ "dame " & @CRLF & _ "lady " & @CRLF & _ "lord " & @CRLF & _ "sir " & @CRLF & _ "COURT: POSITIVE" & @CRLF & _ "the amazing" & @CRLF & _ "the civic-minded" & @CRLF & _ "the elegant" & @CRLF & _ "the eloquent" & @CRLF & _ "the helpful" & @CRLF & _ "the helpful citizen" & @CRLF & _ "the stylish" & @CRLF & _ "the upstanding citizen" & @CRLF & _ "the utterly fluffy" & @CRLF & _ "the wonderful" & @CRLF & _ "COURT: PUNISHMENT" & @CRLF & _ "appallingly filthy" & @CRLF & _ "corpse looter" & @CRLF & _ "dull" & @CRLF & _ "feebleminded" & @CRLF & _ "i got punished" & @CRLF & _ "i got punished and all i got was this lousy title" & @CRLF & _ "i promise i won't do it again" & @CRLF & _ "insignificant" & @CRLF & _ "lying" & @CRLF & _ "malingering" & @CRLF & _ "naughty spawn" & @CRLF & _ "necrokleptomaniac" & @CRLF & _ "offensive" & @CRLF & _ "pillock" & @CRLF & _ "pointless" & @CRLF & _ "repentant" & @CRLF & _ "reprobate" & @CRLF & _ "shopkeeper murderer" & @CRLF & _ "silly spammy git" & @CRLF & _ "sitting in the corner" & @CRLF & _ "smelly" & @CRLF & _ "tantrum thrower" & @CRLF & _ "too stupid to live" & @CRLF & _ "vagrant" & @CRLF & _ "very sorry" & @CRLF & _ "very very sorry" & @CRLF & _ "waste of space" & @CRLF & _ "whinging" & @CRLF & _ "COUNCIL: DJB" & @CRLF & _ "sultan " & @CRLF & _ "sultana " & @CRLF & _ "shai al-khasa " & @CRLF & _ "sitt al-khasa " & @CRLF & _ "shai al-ri'asa " & @CRLF & _ "sitt al-ri'asa " & @CRLF & _ "shai ishquaraya " & @CRLF & _ "sitt ishquaraya " & @CRLF & _ "shai a'daha " & @CRLF & _ "sitt a'daha " & @CRLF & _ "nawab " & @CRLF & _ "qasar " & @CRLF & _ "mazrat " & @CRLF & _ "effendi " & @CRLF & _ "ya'uq " & @CRLF & _ "mutasharid " & @CRLF & _ "ishqaraya " & @CRLF & _ "naughty spawn " & @CRLF & _ "kill stealer " & @CRLF & _ "feebleminded " & @CRLF & _ "idiotic " & @CRLF & _ "offensive " & @CRLF & _ "corpse looter " & @CRLF & _ "cat hating " & @CRLF & _ "heathen " & @CRLF & _ "foreign dog " & @CRLF & _ "infidel " & @CRLF & _ "shopkeeper murderer " & @CRLF & _ "destitute " & @CRLF & _ "parasitic " & @CRLF & _ "hated " & @CRLF & _ "cowardly " & @CRLF & _ "criminal " & @CRLF & _ "felon " & @CRLF & _ "GENUA" & @CRLF & _ "m " & @CRLF & _ "monsieur" & @CRLF & _ "mlle " & @CRLF & _ "mademoiselle" & @CRLF & _ "mme " & @CRLF & _ "madame" & @CRLF & _ "QUEST: POINTS" & @CRLF & _ "well travelled" & @CRLF & _ "persistent" & @CRLF & _ "DEBATERS:" & @CRLF & _ "diplomatic " & @CRLF & _ "uncreative " & @CRLF & _ "THIEVES" & @CRLF & _ "fingers" & @CRLF & _ "ruinous" & @CRLF & _ "WARRIORS" & @CRLF & _ "centurion" & @CRLF & _ "chef" & @CRLF & _ "headmaster" & @CRLF & _ "headmistress" & @CRLF & _ "impaler" & @CRLF & _ "pulveriser" & @CRLF & _ "WITCHES" & @CRLF & _ "destined" & @CRLF & _ "nasty" & @CRLF & _ "terrible" & @CRLF & _ "FOOLS" & @CRLF & _ "pious" & @CRLF & _ "WIZARDS" & @CRLF & _ "erratic mechanic" & @CRLF & _ "arcana" & @CRLF & _ "mysterious" & @CRLF & _ "PRIESTS" & @CRLF & _ "healer" & @CRLF & _ "saintly" & @CRLF & _ "templar" & @CRLF & _ "outcast" & @CRLF & _ "ASSASSINS" & @CRLF & _ "lethal" & @CRLF & _ "venomous" & @CRLF & _ "ALL" & @CRLF & _ "antiquated" & @CRLF & _ "archaic" & @CRLF & _ "axe-master" & @CRLF & _ "bloodthirsty" & @CRLF & _ "bruiser" & @CRLF & _ "captain" & @CRLF & _ "champion" & @CRLF & _ "competent" & @CRLF & _ "contender" & @CRLF & _ "crimewave" & @CRLF & _ "crusher" & @CRLF & _ "cultured" & @CRLF & _ "cutthroat" & @CRLF & _ "deckhand" & @CRLF & _ "decrepit" & @CRLF & _ "diplomatic" & @CRLF & _ "duelist" & @CRLF & _ "elementalist" & @CRLF & _ "energetic" & @CRLF & _ "exterminator" & @CRLF & _ "festive" & @CRLF & _ "filthy" & @CRLF & _ "flatulent" & @CRLF & _ "fossilized" & @CRLF & _ "gifted" & @CRLF & _ "golden" & @CRLF & _ "knifey" & @CRLF & _ "legendary" & @CRLF & _ "literate" & @CRLF & _ "masterful" & @CRLF & _ "medical" & @CRLF & _ "miner" & @CRLF & _ "multilingual" & @CRLF & _ "murse" & @CRLF & _ "mythical" & @CRLF & _ "nimble" & @CRLF & _ "nurse" & @CRLF & _ "obsolete" & @CRLF & _ "old" & @CRLF & _ "old man" & @CRLF & _ "old woman" & @CRLF & _ "opulent" & @CRLF & _ "paranoid" & @CRLF & _ "perverse" & @CRLF & _ "prehistoric" & @CRLF & _ "rock-hard" & @CRLF & _ "rouge" & @CRLF & _ "senile" & @CRLF & _ "shieldmaster" & @CRLF & _ "shieldmistress" & @CRLF & _ "staffmaster" & @CRLF & _ "staffmistress" & @CRLF & _ "stormrider" & @CRLF & _ "swordmaster" & @CRLF & _ "swordmistress" & @CRLF & _ "unburiable" & @CRLF & _ "unexpected" & @CRLF & _ "unlucky" & @CRLF & _ "unstoppable" & @CRLF & _ "venerable" & @CRLF & _ "versatile" & @CRLF & _ "virtuoso" & @CRLF & _ "wealthy" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "Result")

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm