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

const regex = /^(.*)(\r?\n\1)+$/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('^(.*)(\\r?\\n\\1)+$', 'gm') const str = `{"??", "What?"} {"0mg", "Oh My God"}, {"0wn", "owned"}, {"10\\\\/3u", "love you"}, {"13wt", "Loot"}, {"2", "too"}, {"31337", "elite"}, {"4tw", "for the win"}, {"A&D", "Attack and Defend"}, {"AFAIK", "As Far As I Know"}, {"AFK", "Away from keyboard"}, {"ASL", "Age Sex Location"}, {"ATM", "At The Moment"}, {"BAF", "Bring A Friend"}, {"BBIM", "Be Back In a Minute"}, {"BBL", "Be Back Later"}, {"BBS", "Be Back Soon"}, {"BFG", "big fucking gun"}, {"BRB", "Be Right Back"}, {"BS", "Bullshit"}, {"BTW", "By The Way"}, {"Camper", "Ambush"}, {"CFT", "Capture the flag"}, {"CTF", "Capture the Flag"}, {"CU", "See You"}, {"d00d", "Dude"}, {"DM", "Death Match"}, {"DMG", "Damage"}, {"dog8", "dog"}, {"duma**", "idiot"}, {"eet", "elite"}, {"em", "Them"}, {"exp", "experience points"}, {"EXP", "Experience Points"}, {"f00", "Fool"}, {"FAQ", "Frequently Asked Questions"}, {"FB", "Flash Bang grenade"}, {"FFA", "Free For All"}, {"FFS", "For Fuck's Sake"}, {"FH", "Full Health"}, {"Flak", "Debris"}, {"Flame", "Nonstop insulting"}, {"form", "from"}, {"FPS", "First Person Shooter"}, {"fragged", "killed"}, {"ftw", "for the win"}, {"G2G", "Got To Go"}, {"GA", "Go Ahead"}, {"GD", "God Damn"}, {"GF", "Good Fight"}, {"GG", "Good Game"}, {"GGA", "Good Game All"}, {"gimme", "Give me"}, {"GL", "Good Luck"}, {"Going Gold", "publishing of software"}, {"grill", "girl"}, {"guise", "guys"}, {"h@", "Hat"}, {"h4x", "hacks"}, {"h4x0r", "hacker"}, {"h8", "Hate"}, {"hai", "hi"}, {"high-ping bastard", "crappy internet"}, {"HP", "Health Points"}, {"IIRC", "If I Recall Correctly"}, {"IMHO", "In My Honest Opinion"}, {"IMO", "In My Opinion"}, {"instagib", "unlimited ammo"}, {"IRC", "Internet Relay Chat"}, {"IRL", "In Real Life"}, {"j0", "Yo!"}, {"J00", "You!"}, {"JJ", "Just Joking"}, {"JK", "Just Kidding"}, {"kewl", "cool"}, {"kicked", "banned cheater"}, {"kk", "ok"}, {"KOS", "Kill On Sight"}, {"l@ym", "laughing at your momma"}, {"l337", "elite"}, {"l33t", "Elite"}, {"l4m3r", "lamer"}, {"level up", "Improving"}, {"liek", "like"}, {"lobby", "chat room"}, {"LOL", "Laughs out loud"}, {"lopl", "lol"}, {"low-ping bastard", "fast internet"}, {"Lvl", "Level"}, {"m2", "me too"}, {"m8", "mate"}, {"Mana", "cast magical spells"}, {"mastah", "master"}, {"max0r", "max"}, {"Med", "Medic"}, {"meh", "oh well"}, {"MMORPG", "Massive Multiplayer Online Role Playing Game"}, {"Mod", "A modification of a game"}, {"MP", "Multiplayer"}, {"MTFBWY", "May The Force Be With You"}, {"n00b", "newbie"}, {"N1", "Nice one"}, {"Nade", "Grenade"}, {"nd", "and"}, {"Nerfed", "bad bug"}, {"newb", "newcomer"}, {"nooblet", "newcomer"}, {"np", "No problem"}, {"NT", "nice try"}, {"OLO", "LOL"}, {"OMDG", "oh my dance"}, {"OMFG", "Oh My Fucking God"}, {"OMG", "oh my god"}, {"OMGWTFBBQ", "Oh My God What The Fuck Barbecue"}, {"OMW", "On My Way"}, {"OOR", "Out Of Range"}, {"OOS", "Out Of Sight"}, {"ORLY", "Oh, really?"}, {"ORLY", "Oh, really?"}, {"OSOK", "One Shot One Kill"}, {"own", "own"}, {"ownage", "superior"}, {"p0wn", "pawned"}, {"ph33r", "Fear me"}, {"phear", "fear"}, {"PITA", "Pain In The Arse/Ass"}, {"PK", "Player Killing"}, {"pl0x", "please"}, {"PMGZ", "OMG"}, {"PMSL", "Pissing MySelf Laughing"}, {"Polishing", "final touches"}, {"Port", "Teleport"}, {"powwah", "power"}, {"Pr0n", "porn"}, {"pwnage", "superior"}, {"pwnt", "superior"}, {"r", "are"}, {"r0x0r", "dude that rocks!"}, {"rgr", "Roger"}, {"ROFL", "Rolls on the floor laughing"}, {"ROFLMAO", "Rolling On the Floor Laughing My Ass Off"}, {"rox", "Rocks"}, {"RP", "Role Play"}, {"RPG", "Role-Playing Game"}, {"RT", "Roger That"}, {"RTFM", "Read the f***ing manual"}, {"RTS", "Real-Time Strategy"}, {"Sig", "Signature"}, {"sk1llz", "Skills"}, {"Slug", "A large, non-self-propelled projectile"}, {"smat", "smart"}, {"SP", "Single Player"}, {"Spam", "Repeatedly messaging the same messages"}, {"spawn", "reborn"}, {"sry", "Sorry"}, {"STFU", "Shut The Fuck UP"}, {"sup", "What's Up"}, {"sux0r", "Sucks"}, {"taunt", "Provoking"}, {"TBH", "To Be Honest"}, {"teh", "the"}, {"Thx", "Thanks"}, {"TPS", "Third Person Shooter"}, {"Ty", "Thank you"}, {"u", "you"}, {"w8", "wait"}, {"wat", "what"}, {"WB", "Welcome Back"}, {"wen", "when"}, {"whut", "what"}, {"winnar", "winner"}, {"wot", "what"}, {"WTF", "What the f***?"}, {"WTG", "Way To Go"}, {"WYG", "What You Got?"}, {"y", "why"}, {"ya", "yeah"}, {"yass", "yes"}, {"yea", "yeah"}, {"yos", "yes"}, {"yus", "yes"}, {"ZPMG", "OMG"},`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions