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

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

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html