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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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 = /.{5}-.{5}-.{5}/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('.{5}-.{5}-.{5}', 'gm') const str = `45Y43-04T52-JDLH2 8YZIH-2QKFB-3KFFQ 44P78-J74GI-4L9AF BTHGF-WL500-C0R4V 6RM9G-N9XFP-VCJRQ IEA6K-QMFHN-YVYP9 XNWHC-PR7XT-NP2KL JRFCZ-XDQB3-4YRX3 4V8YN-L0DRV-CIWJ7 56LPR-3B48C-746IK BDFW4-V9NZ5-JGTKZ L2FJZ-DBC2I-4CA53 GEBFT-A8W6J-NHNA5 6BRKC-TJZBC-W7E4E Tanuki Sunset (2020) Skateboarding Racoons Redemption Key: EZ6KQ-Q843I-4VR2K Swords 'n Magic and Stuff EA (2020) Cute Multiplayer RPG Redemption Key: V9KCM-ETNCK-783FC Sunlight (2021) Chilled, wholesome trees Redemption Key: 6XBXM-PLY8B-BH6ZI Space Crew (2020) Space Management Adventure Redemption Key: I24W9-5HVWA-WVVF0 Sok-worlds (2020) Popping Micro-games Redemption Key: KLDH9-6MN8R-HGIM8 Seals of the Bygone EA (2020) Roguelike Dungeon Delver Redemption Key: 5K984-GVM78-M0XKI Pyramida (2020) Popping Micro-games Redemption Key: VDVCZ-VQDFA-RGTD2 Primal Light (2020) 16bit Boss Battler Redemption Key: CIIF5-YZCV3-D5W5Z Popo's Tower (2020) Popping Micro-games Redemption Key: M8F2X-M39FD-X2QEC Pocket Watch (2020) Popping Micro-games Redemption Key: CTENC-YQRX2-WJFDE PlateUp! (2022) Brilliant Cooking Chaos Redemption Key: LCW28-X8FNM-PMC25 Plague Inc: Evolved (2016) End The World Redemption Key: C7DJ7-P89MM-XNP6F Pendragon (2020) Mythic Tactical Narrative Redemption Key: F7AAG-9J2M4-2ZP7W Paradise Lost (2021) Postapocalyptic Adventure Redemption Key: ZJP3N-YW9BJ-9QLNA Paperball (2020) Stunt Ball Racing Redemption Key: JXBRJ-B20WN-6YZDT Orbi Universo (2020) Abstract Civ Strategy Redemption Key: RBBXD-02R4I-ZBCWN Moon Hunters (2016) Tiny DnD Adventures Redemption Key: 6QPQ5-Y4XYI-MWXRX Men of War: Assault Squad 2 (2014) Tanks Troops Tactics Redemption Key: 0BA6C-39RXP-LF0P2 Mech Mechanic Sim (2021) Build-a-mech workshop Redemption Key: C45EI-0G6HZ-VWWW4 Maiden and Spell (2020) Flying Magic Bullet-hell Redemption Key: 54EGK-4WR22-F2CPT Mad Experiments: Escape Room (2020) Mind-bending Escape Room Redemption Key: T896H-F6XHH-H77PJ Lucifer Within Us (2020) Intricate Demonic Detective Redemption Key: QJNJ6-R709L-JZJ27 Lost Nova (2022) Explore Build Craft Redemption Key: YD66M-DW407-TXBY4 Little Inferno (2012) Burn Your Toys Redemption Key: 2FDDH-BVHCF-ZGMRG Kitaria Fables (2021) ARPG with Farming Redemption Key: CR79H-XXQ39-XR326 King Pins (2020) Popping Micro-games Redemption Key: G664K-X90Y4-TI3JL KILLRUN (2022) Run Gun Parkour! Redemption Key: ZQMBT-8LLNX-PLP6W Kaiju Wars (2022) Monster Mashing Tactics Redemption Key: JBAMA-7DNZT-PCFK9 JARS (2021) Creepy Puzzles Redemption Key: MJY23-KB8DY-AVM9E Imagine Earth (2021) Planetary Colonization Redemption Key: IRENW-AD95D-W8XZY Idle Champions - Prismeer Sentry Skin & Feat Pack (2022) Buff Your Champion Redemption Key: 3H8T8-JD6C0-WTFEL Idle Champions - Polymorphed Shandie Skin & Feat Pack (2022) Buff Your Champion Redemption Key: D29T4-W9JV6-YZB6C House (2020) Spooky Pixel House Redemption Key: 3EZRM-9F8E8-4BD0R Here Comes Niko! (2021) Cute Cozy Platforming Redemption Key: XXBKJ-KNQ7R-BKPYZ Hellblusser (2021) Popping Micro-games Redemption Key: C4IC8-5YY5B-8NMLM Geneshift EA (2017) Cars Guns Action Redemption Key: ELNYT-TM9C6-36NNC Fury Unleashed (2020) Frantic Roguelike Shooter Redemption Key: M96X5-5647E-VXFEL Fresh Store Discount 25% off these collections; RTGame, High Rollers, Hat Films, Spiffing Brit & ISP, active from Dec 1 to Jan 17590 Redemption Key: 25HN26 Flipper Volcano (2020) Popping Micro-games Redemption Key: HA84M-BAA6B-WXWG2 Fit For a King (2019) Marry Divorce Execute Redemption Key: BCA7H-8KYAT-RYZ45 First Class Trouble (2021) Cruise Ship Among Us Redemption Key: XWM5E-8NV7T-6P0HE Final Vendetta (2022) Side Scrolling Brawler Redemption Key: ABW65-X9YX8-0L8L3 Fanatical spinning wheel redeem your code here: https://www.fanatical.com/en/redeem-code Redemption Key: RCtG6PHzzcXXsr Factory Town (2021) Automate Your Town Redemption Key: VTMA4-05TF8-7RVK9 Eternal Hope (2020) Cinematic Puzzle Platformer Redemption Key: 4YFK3-CL7B0-K2559 Epic Battle Fantasy 5 (2018) Tongue-in-cheek JRPG Redemption Key: YBJWL-VZRAH-9LQIB Dude, Stop (2018) Be Annoying Redemption Key: XFHWM-T5C33-BT9JW Driftland: The Magic Revival (2019) Floating Wizards 4X Redemption Key: CEKXL-34ARQ-W622F Displate Discount code 40% off at displate (redeemable on the displate website) Redemption Key: CD2N2KZ7 Discolored (2019) Perform Pigment Puzzles Redemption Key: BFP3L-KHCQH-CYYJQ DESOLATE (2019) Coop Zombie Survival Redemption Key: 4AVFQ-MHV3F-TEH33 Deponia (2014) Iconic Point-and-Click Redemption Key: YNMK3-87GGA-7GIBR Demolish & Build 2018 (2018) Knock Stuff Over Redemption Key: K4LE8-VLEG2-5D92N delta: Rings of Saturn (2019) Realistic Space Mining Redemption Key: J3K05-7G406-7DQDP Dark Nights with Poe and Munro (2020) Supernatural FMV Strangeness Redemption Key: TPW4R-CAZ67-AX7II Danger Scavengers (2021) Cyberpunk Rooftop Romp Redemption Key: 4F0DX-W4T09-3JIQC CryoFall (2021) Sci-fi Multiplayer Survival Redemption Key: 4P6KY-40C3X-3ENQR Crazy Machines 3 (2016) Wacky Physics Sandbox Redemption Key: T3QXN-V0WR8-4JKVV ConnecTank (2021) Coop Conveyer Battles Redemption Key: AYZVT-D8F8B-LW9IJ Concrete Jungle (2015) Classic City Builder Redemption Key: WJG8H-BR0VM-0HIZE City Climber (2017) Ragdoll Climbing Fun Redemption Key: C7LPY-ZD0ZM-638X2 CHUCHEL (2018) Comedy Mushroom Adventure Redemption Key: GEW0J-CW9BJ-HHGT4 Chronicon (2020) Live Loot Level-Up Redemption Key: HE8CZ-3LPE6-RKJW3 Chroma Squad (2015) Power Ranger Manager Redemption Key: R2QGM-JIH70-57H2Q Chatventures (2020) Popping Micro-games Redemption Key: CKTGT-LWT97-4TH2C Chaos Reborn (2015) Tactical Wizard Wars Redemption Key: 4AMFE-PEEFN-4IE2X Bonfire Peaks (2021) Atmospheric Burning Puzzles Redemption Key: DL3EA-4C2VD-TFB3M Big Crown Showdown (2018) Frantic Fall-Knights Redemption Key: AL4G8-CFJ06-GL0X6 Ato (2020) Cat Samurai Adventure Redemption Key: EDE9C-8YNTQ-H9CXT Aporia: Beyond The Valley (2017) Stunning Story Puzzler Redemption Key: KJI3R-6FMTH-9KJ6H Ancient Enemy (2020) Modern Fantasy Solitaire Redemption Key: 0JYQ0-W5QXM-9LW3Y Age of Wonders: Planetfall (2019) Beautiful Sci-Fi 4X Redemption Key: 447DM-IW4Y7-TZRMG Aeronautica Imperialis: Flight Command (2020) Turn-based Top Gun Redemption Key: KPH7N-22L7D-AX5TD Absolute Drift (2015) Chill Drifting Redemption Key: YWHF9-6KTFI-CPRLL A Total War Saga: TROY (2021) Swords Sandals Slaughter Redemption Key: K4B0G-6WA7G-3XN25 `; 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