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

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?m)^([A-Z][A-Z])" Local $sString = "EPISODE 148: The Flea Party" & @CRLF & _ " " & @CRLF & _ "TAFFY" & @CRLF & _ "Per-fect!" & @CRLF & _ "BENTLEY" & @CRLF & _ "Gotcha!" & @CRLF & _ "MRS M" & @CRLF & _ "Aaaah! I must ask Forsythe not to leave his kitchen cabinets lying around on the floor like this!" & @CRLF & _ "MRS M" & @CRLF & _ "Oh my! I hope my little cherub doesn’t have fleas or I’ll have to take that ribbon right off and put a flea collar on you!" & @CRLF & _ "TAFFY" & @CRLF & _ "Take the ribbon off?" & @CRLF & _ "TAFFY" & @CRLF & _ "Fleas? Please! This is just a common itch, I don’t have fleas." & @CRLF & _ "BENTLEY" & @CRLF & _ "Oh no? Well you will my friend, you will. And I know just where to find them" & @CRLF & _ "FLEA 1" & @CRLF & _ "Cookie crumb?" & @CRLF & _ "FLEA 2" & @CRLF & _ "Don’t mind if I do." & @CRLF & _ "MISH" & @CRLF & _ "Moldy macaroon?" & @CRLF & _ "MASH" & @CRLF & _ "Thank you kindly!" & @CRLF & _ "MISH & MASH " & @CRLF & _ "One for me, one for flea." & @CRLF & _ "MASH" & @CRLF & _ "Enjoy, little dudes!" & @CRLF & _ "MISH" & @CRLF & _ "Ouch! Hey, what was that?!" & @CRLF & _ "MASH" & @CRLF & _ "Ow! Keep yer paws off my hairdo!" & @CRLF & _ "MISH" & @CRLF & _ "Me!? You’re the one pocking my hair!" & @CRLF & _ "MASH" & @CRLF & _ "Are you kidding me?" & @CRLF & _ "MISH" & @CRLF & _ "Liar!" & @CRLF & _ "MASH" & @CRLF & _ "What did you say?" & @CRLF & _ "MISH" & @CRLF & _ "I said…" & @CRLF & _ "MASH" & @CRLF & _ "Moldy macaroon?" & @CRLF & _ "MISH" & @CRLF & _ "Don’t mind if I do." & @CRLF & _ "FLEA" & @CRLF & _ "HEY LET US OUT!!!" & @CRLF & _ "BENTLEY" & @CRLF & _ "Yeah, yeah, be patient" & @CRLF & _ "FLEA 1" & @CRLF & _ "Oh! Love that new host smell!" & @CRLF & _ "You said it! Let’s settle here!" & @CRLF & _ "BENTLEY" & @CRLF & _ "Look! Fleas! Fleas!!! Whoo whoo whoo, fleas !" & @CRLF & _ "MRS M" & @CRLF & _ "Oh dear! you’re not scratching again are you?" & @CRLF & _ "BENTLEY" & @CRLF & _ "Go ahead, scratch it up! You know you want to." & @CRLF & _ "MRS M" & @CRLF & _ "Delightful dinero, a discothèque!" & @CRLF & _ "MRS M" & @CRLF & _ "Like summer nights in Salamanca." & @CRLF & _ "MRS M" & @CRLF & _ "Don’t be a party pooper, Bentley, dance with your little brother!" & @CRLF & _ "Flea" & @CRLF & _ "Earthquake!" & @CRLF & _ "Flea" & @CRLF & _ "Let’s move from this place!" & @CRLF & _ "MRS M" & @CRLF & _ "Coming!" & @CRLF & _ "TAFFY" & @CRLF & _ "Huh. I don’t itch anymore." & @CRLF & _ "BENTLEY" & @CRLF & _ "Of COURSE you do! You’re covered in flea-AA!" & @CRLF & _ "" & @CRLF & _ "MRS M" & @CRLF & _ "Bentley, now you?! And it looks like you might need more than a flea collar, you may need a HOT FLEA BATH." & @CRLF & _ "MRS M" & @CRLF & _ "Sorry dear, what was that again? " & @CRLF & _ "TAFFY" & @CRLF & _ "Ah! That will teach you to start a flea fight" & @CRLF & _ "MRS M" & @CRLF & _ "Well if you can’t decide, why not buy BOTH yachts, dear?" & @CRLF & _ "MRS HIGHCOST" & @CRLF & _ "Hello? Are you still there?" & @CRLF & _ "MRS M" & @CRLF & _ "Oh sorry darling. Can you get them in platinum?" & @CRLF & _ "TAFFY" & @CRLF & _ "I love scratching" & @CRLF & _ "TAFFY" & @CRLF & _ "Scratch scratch scratch scratch" & @CRLF & _ "MRS HIGHCOST" & @CRLF & _ "So… Platinum or diamond then?" & @CRLF & _ "MRS M" & @CRLF & _ "Oh sorry dear, let’s have a look in the magazine" & @CRLF & _ "TAFFY" & @CRLF & _ "Here buddy, this will help!" & @CRLF & _ "BENTLEY" & @CRLF & _ "Oh! Itchy wool!" & @CRLF & _ "MRS M " & @CRLF & _ "Well of course matching helicopters! What are we? Cave people?" & @CRLF & _ "FORSYTHE" & @CRLF & _ "I’ve nearly achieved...PERFECTION!" & @CRLF & _ "FORSYTHE" & @CRLF & _ "Out of my kitchen you fleabag!" & @CRLF & _ "MRS M " & @CRLF & _ "Animal control, I have a flea emergency!" & @CRLF & _ "MASH" & @CRLF & _ "There you are! We found you!" & @CRLF & _ "TAFFY" & @CRLF & _ "Found me?" & @CRLF & _ "MASH" & @CRLF & _ "Not you-– them!" & @CRLF & _ "MISH & MASH" & @CRLF & _ "Welcome home fellas!" & @CRLF & _ "See ya!" & @CRLF & _ "ANIMAL CONTROL " & @CRLF & _ "This is worse than the Itchy Dingo Disaster of ‘05." & @CRLF & _ "TAFFY" & @CRLF & _ "Showtime!" & @CRLF & _ "MRS M " & @CRLF & _ "Oh my hair!" & @CRLF & _ "Oh! What a wonderful haircut for this summer! " & @CRLF & _ "Thank you Taffy-Waffy" & @CRLF & _ "" Local $sSubst = " \1" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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