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 the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r"(?m)^(?<prefix>.?)\[(?<code>[ABCDEFabcdef0123456789]{6})\](?<suffix>.*?)(\[-\])").unwrap(); let string = "[E16213]Calories: 1[-] Crafting ingredient Amanita Mushroom Amanita Mushrooms [E16213]Calories: 10[-] Poisonous Arm Arms [E16213]Calories: 600[-] Arrows Batteries Refills torch Blackberries [E16213]Calories: 1[-] Blue Paint Crafting ingredient BlueBerries [E16213]Calories: 1[-] Blueberry Bush Seed Blueberry Bush Seeds Use in gardens Bone Bones Crafting ingredient Bone Armor Increases [ffce00]Armor[-] Booze [E16213]Calories: 200[-] Crafting ingredient Broken Toy Broken Toys A piece of Timmy's toy Camcorder Find tapes to view Cash Use to stoke fires Cassette 1 Fatal Request - \\\"Stronghold\\\" Cassette 2 The Slaps - \\\"No Conscience\\\" Cassette 3 Frankie Millionaire -\\\"Do It\\\" Cassette 4 Wolf on Fire - \\\"The Haunting\\\" Cassette 5 Rick Gold - \\\"S,A,W\\\" Cassette Player Cassette Players Restores [02a1ff]Energy[-] Cave Map Cave Maps Chainsaw Chanterelle Mushroom Chanterelle Mushrooms [E16213]Calories: 10[-] Chicory [E16213]Calories: 1[-] Crafting ingredient Circuit Board Circuit Boards Crafting ingredient Climbing Axe Climbing Axes Cloth Crafting ingredient Club Clubs Coins Crafting ingredient Compass Compasses Coneflower [E16213]Calories: 1[-] Crafting ingredient Coneflower Seed Coneflower Seed Use in gardens Crafted Axe Crafted Axes Crafted Bow Crafted Bows Crafted Club Crafted Clubs Deer Mushroom Deer Mushrooms [E16213]Calories: 10[-] Deer Skin Crafting ingredient Dynamite Electrical Tape Electrical Tapes Crafting ingredient Energy Mix Increases Stamina Energy Mix + Greatly increases stamina Explosive Explosives Feather Feathers Crafting ingredient Fire Torch Fire Torches Fish [E16213]Calories: 500[-] Use on fire Flare Flares Flare Gun Flare Guns Flare Gun Ammo Refills flare Gun Flintlock Pistol Flintlock Pistols Fuel Can Fuel Cans Refills chainsaw Meat [E16213]Calories: 600[-] Use on fire Gold Keycard Use on door Head Heads Use on fire Head Bomb Head Bombs Jack Mushroom Jack Mushrooms [E16213]Calories: 10[-] Katana Katanas Keycard Keycards Use on door Leaf Leaves Crafting ingredient Leg Legs [E16213]Calories: 600[-] LibertyCap Mushroom LibertyCap Mushrooms [E16213]Calories: 10[-] Lighter Lighters Lizard Lizards [E16213]Calories: 600[-] Use on fire Lizard Skin Increases [ffce00]Armor[-] Log Logs Machete Map 1/4 Torn part of map Map 2/4 Torn part of map Map 3/4 Torn part of map Map 4/4 Torn part of map Map Cave 2 Marigold [E16213]Calories: 1[-] Crafting ingredient Meds Restores [ff0404]Health[-] Health Mix Restores [ff0404]Health[-] Health Mix + Restores [ff0404]Health[-] Metal Tin Tray Metal Tin Trays Share items Modern Axe Modern Axes Modern Bow Modern Bow Molotov Molotovs Old Gun Ammo Crafting ingredient Old Gun Part 1 of 8 Crafting ingredient Old Gun Part 2 of 8 Crafting ingredient Old Gun Part 3 of 8 Crafting ingredient Old Gun Part 4 of 8 Crafting ingredient Old Gun Part 5 of 8 Crafting ingredient Old Gun Part 6 of 8 Crafting ingredient Old Gun Part 7 of 8 Crafting ingredient Old Gun Part 8 of 8 Crafting ingredient Old Photo 1 of 8 Old Photo 2 of 8 Old Photo 3 of 8 Old Photo 4 of 8 Old Photo 5 of 8 Old Photo 6 of 8 Old Photo 7 of 8 Old Photo 8 of 8 Old Pot Old Pots % Use to boil water Orange Paint Crafting ingredient Oyster Oysters [E16213]Calories: 10[-] Passenger Manifest Passenger Manifests Find the missing passengers! Pedometer Pedometers [00fff4]Steps Taken[-] % Plane Axe Plane Axes Plastic Torch Plastic Torches BATTERY: % Pouch Pouches Use to collect berries Puff Mushroom Puff Mushrooms [E16213]Calories: 10[-] Quiver Quivers Holds extra arrows Rabbit Rabbits [E16213]Calories: 600[-] Use on fire Rabbit Fur Crafting ingredient Rabbit Fur Boots Increases stealth Rebreather Rebreathers Swim further underwater Repair Tool Repairs structures Rock Rocks Rock Bag Rock Bags Holds extra rocks Rope Ropes Crafting ingredient Rusty Axe Rusty Axes Skull Skulls Crafting ingredient Slingshot Slingshots Small Meat [E16213]Calories: 300[-] Use on fire Snack Snacks [E16213]Calories: 400[-] Restores [02a1ff]Energy[-] Snow Shoes Walk faster in snow Snowberries [E16213]Calories: 1[-] Soda Sodas [E16213]Calories: 400[-] Restores [02a1ff]Energy[-] Stealth Armor Increases stealth Stick Sticks Stick Bag Stick Bags Holds extra sticks Survival Guide Survival Guides Book on survival Tape labeled 'armsy breakout' View on camcorder Tape labeled 'Lunch with Megan' View on camcorder Tape labeled 'Megans arrival' View on camcorder Tape labeled 'Opening the artifact' View on camcorder Tape labeled 'Second Artifact Test' View on camcorder Tape labeled 'Side effects' View on camcorder Tennis Racket Tennis Rackets Small Rock Small Rocks Slingshot ammo Small Rock Bag Small Rock Bag Holds extra small rocks Timmy Drawings Use as decorations Timmy's Toy Tooth Teeth Crafting ingredient Tree Sap Crafting ingredient Turtle Shell Turtle Shells Use as a sled TwinBerries [E16213]Calories: 1[-] Upgraded Rock Upgraded Rocks Upgraded Spear Upgraded Spears Use to catch fish Upgraded Stick Upgraded Sticks Walkie Talkie Walkie Talkies Communicate With friends Waterskin Waterskins % Holds water Weak Spear Weak Spears Use to catch fish Wristwatch Wristwatches Crafting ingredient Spear Bag Holds extra spears Hairspray Use with lighter Boar Skin Crafting ingredient Raccoon Skin Crafting ingredient Artifact ??? Warmsuit Protects from cold Creepy Armor Increases [ffce00]Armor[-] Timmy photo CrossBow CrossBow Bolt CrossBow Bolts Raw {0} Dried {0} Fresh Edible Spoilt (Equiped) clean water polluted water Empty drink Eat Use Store Found passenger, seat collected You have been kicked You have been banned by Host You have been banned by Host You have been kicked {0} DAYS {1} HOURS {2} MINUTES {3} SECONDS NEW PATCH RELEASING SOON : DAY PLAYERS: {0} / {1} play read take charge wear new item added to todo list to do list updated +Speed {0} +Damage -Speed {0} +Damage {0} Sticky {0} Burning {0} Orange {0} Blue {0} Recharged {0} Extra burning {0} Incendiary {0} Bone {0} {0} AMMO NEW PLANT DISCOVERED NEW ANIMAL DISCOVERED Poisoned {0} Creating Lobby... Talking to Steam... Starting Server... Joining Lobby {0}... Starting Client... Talking to PSN... Could not create Steam lobby. Could not create PSN lobby. Could not connect to Steam master server. Could not connect to PSN master server. Could not start PSN game server. Could not start Steam game server. Could not join Steam lobby. Could not join PSN lobby. Lobby Destroyed {0} with light and UNEQUIP GOOD COLD IN PAIN THIRSTY HUNGRY WEAPON A Basic fire that keep you warm during cold nights Build a Fire. It can be used to keep warm,\\nlight up dark nights or scare off enemies\\nbut be warned at night fires may attract\\nunwanted attention to your base. Eating food is the best way to keep your\\nEnergy Levels high. Learn about more\\nvarieties in the Food Section of this book. Berries are a dark shiny black colour and\\nform in pairs A large longer lasting fire that can be seen from afar Store live rabbits in a cage and watch them multiply Ideal for drying and preserving meats A longer lasting fire that you can also relight if it goes out Use this fire type to light your camp at night Plant seeds to grow food close to your shelter Weight Store rainwater close to your shelter HINT: COVER YOURSELF IN MUD TO HIDE FROM ENEMIES HINT: BEING COLD WILL DRAIN YOUR ENERGY HINT: KEEP YOUR ENERGY UP BY EATING REGULARLY HINT: YOU CAN REGAIN ENERGY BY RESTING ON BENCH HINT: EXPLOSIVES AND MOLOTOVS ARE EFFECTIVE AGAINST MOST ENEMIES HINT: TRY UPGRADING YOUR WEAPONS HINT: YOU CAN MAKE ARMOR OUT OF LIZARD SKIN HINT: LIT EFFIGIES WILL SCARE ENEMIES AWAY FROM YOUR CAMP HINT: HIDE IN BUSHES TO ESCAPE FROM ENEMIES HINT: BUILD A SHELTER TO SAVE YOUR GAME HINT: FIND A POT TO BOIL WATER ACTION ADJUST BRIGHTNESS CONTROLLER SPEAKER ALT ACTION AUDIO MODE BARELY\\nVISIBLE CAMERA CAMERA, PRESS TO CROUCH CLEARLY\\nVISIBLE INVENTORY ITEM JUMP LIGHTER MAP MOVE, PRESS TO SPRINT NOT\\nVISIBLE PERFORMANCE MODE STEREO\\nSURROUND\\nSMALL TV\\nHEADPHONES\\nNIGHT MODE\\nSTREAMER ROTATE BUILDING SURVIVAL GUIDE TAKE/BUILD UTILITY PREVIOUS CHAPTER NEXT CHAPTER PREVIOUS PAGE NEXT PAGE HORIZONTAL RIGHT LEFT VERTICAL FORWARD BACKWARD LOOK X LOOK RIGHT LOOK LEFT LOOK Y LOOK UP LOOK DOWN RUN CROUCH PRIMARY FIRE REST CRAFT ITEM SLOT 1 ITEM SLOT 2 ITEM SLOT 3 ITEM SLOT 4 WALKY TALKY BATCH PLAYER LIST RED BEANIE BLUE BEANIE GREEN BEANIE BLUE JEANS BLACK JEANS CAMO JEANS KHAKI JEANS BEIGE CARGO PANTS BLACKSUIT DARKGREY HOODIE GREY HOODIE GREEN HOODIE JACKET LEATHER JACKET CLOSED SHIRT OPEN SHIRT DARKBLUE VEST DARKGREEN VEST COLORFUL VEST WHITE TSHIRT CAMO TSHIRT WOLF TSHIRT GREY TSHIRT BLUE BUTTON UP SHIRT WHITE BUTTON UP SHIRT GREY LONG SHIRT BLACK VNECK SHIRT STEWARDESS DRESS BATHROBE BATHROBE PANTS TENNIS OUTFIT PILOT UNIFORM OLD SUIT ALPINE TREEHOUSE ANIMALS 1 ANIMALS 2 ANIMALS 3 Arm Effigy ARMOR RACK ARROW BASKET BASIC SIMPLE STAIRS BASIC STRUCTURES BASIC WALL WALL WITH DOOR WALL WITH WINDOW BASIC FIRE BASICS OF SURVIVAL TUTORIAL BASICS OF SURVIVAL 2 STICKS 6 ROCKS 7 LOGS 7 STICKS STEP ONE Build a shelter. \\nA shelter can be used to sleep \\nand to save your game.\\n Consider Building a shelter before heading out \\ninto the unknown woods. 7 LEAVES STEP TWO Build a fire. \\nIt can be used to keep warm, light up \\ndark nights or scare off enemies but \\nbe warned at night, fires may \\nattract unwanted attention. Fire is extremely valuable in a survival situation. \\nYou can also use fire or a torch to light your way\\n in dark caves. THE BERRIES ARE AN\\r\\n<color=#9370DBFF>INDIGO COLOUR</color> AND\\r\\nHAVE A LITTLE CROWN\\r\\nON THE TIP. EDIBLE FORAGING POISONOUS STEP THREE BERRIES ARE A DARK\\r\\nSHINY <color=#000000FF>BLACK COLOUR</color>\\r\\nAND FORM IN PAIRS. Here is an example of two similar looking berries. \\nOne is edible, the other poisonous. Be careful, use reference \\nand make sure you know what you\\u2019re eating \\nbefore you eat it. BIRDHOUSE BOATS BONE CHAIR BONE CHANDELIER BONE FRAME BONE BASKET BONE FENCE BON FIRE CAR CATAPULT CEILING SKULL LAMP CHAIR CHURCH CLIMBING ROPE LOG TRACK COFFIN COUCH TO CRAFT AN ITEM, YOU NEED TO\\nCOLLECT THE REQUIRED AMOUNT\\nOF RESOURCES CRAFTING CRAFTING GUIDE CRAFTING GUIDE CRANE CROSS CUSTOM BUILDING CUSTOM 1 CUSTOM 2 CUSTOM 3 RABBITSKIN DECORATIVE SKULL HEAD TROPHY WALL PLANTER WEAPON DISPLAY DEERSKIN DECORATIONS DECORATIONS 1 DECORATIONS 2 DECORATIONS 3 DEFENSIVE SPIKES DEFENSIVE WALL SPIKES DEFENSIVE WALLS DOCK DOG DRYING RACK Effigies PROPS Custom Effigy Large Effigy RAIN EFFIGY Small Effigy ELEVATED EXPLOSIVES HOLDER FAMILY FIRE FIRE PIT FIREPLACE STANDING FIRE CUSTOM FLOOR FOOD FOOD AND WATER CUSTOM FOUNDATION FURNITURE FURNITURE 1 FURNITURE 2 GARDEN GAZEBO GLIDER HOLE CUTTER HOUSE BOAT HUNTING SHELTER THIS BOOK CONTAINS INSTRUCTIONS TO\\r\\nBUILD THE TOOLS AND ITEMS YOU NEED TO\\r\\nSURVIVE ALONE IN THE WILDERNESS SURVIVAL OVAL-LEAVES BLUEBERRIES BLACK TWINBERRY ITEMS NEEDED: LARGE CABINET LARGE RAFT LEAF PILE TRAP LOG CABIN SMALL CABIN LOG HOLDER LOG SLED MAIN INDEX NATURE GUIDE NATURE GUIDE ALOE BIG BROWN BAT BLACK TWINBERRY BLACKBERRIES BLUEBIRD BLUECHEEK BUTTERFLYFISH BOAR CANADA GOOSE CARDINAL CARP CAVE FISH CHANTERELLE MUSHROOM CHICORY COD CONEFLOWER CROCODILE CROW DANDELION DEER DEER MUSHROOM EUROPEAN RABBIT FIREWEED FLY AGARIC GLAUCOUS WINGED GULL GOANNA LIZARD GREAT WHITE SHARK HORSETAIL JACK O LANTERN MUSHROOM LIBERTY CAP MUSHROOM LOGGERHEAD\\nSEA TURTLE MARIGOLD OVAL-LEAVES BLUEBERRIES PALETTE SURGEONFISH POISON PUFF\\nMUSHROOM RACCOON ROBIN ROCK BEAUTY SNOWBERRY SNOWSHOE RABBIT SQUIRREL THISTLE TORTOISE YELLOWTAIL TANG NOTES PLANT LIFE 1 PLANT LIFE 2 PLATFORM RABBIT CAGE RABBIT TRAP SMALL RAFT ROCK PATH ROCK HOLDER ROCK WALL CUSTOM ROOF SHELTERS SIDE TABLE SIGNALS BUILD A SIGNAL. NEVER GIVE UP HOPE. TIMMY SITTING WIFE SITTING SKIN RACK SKULL LAMP SMALL BED SMALL CABINET SOS SIGN CUSTOM STAIRS TIMMY ARMOR COLD ARMOR ATHLETICISM CONDITIONS: CURRENTLY FEELING DAYS SURVIVED ENERGY FULLNESS HEALTH HYDRATION Infected\\nfind aloe to heal SANITY Sick\\nfind aloe to cure or get some rest STAMINA STEALTH STRENGTH WEIGHT STATS STATS STEP ONE STEP THREE STEP TWO STICK FRAME STICK FENCE STICK HOLDER STICK MARKER STORAGE STORAGE1 STORAGE2 STORAGE3 TABLE WOOD TARGET explore chasm cave explore dead cave explore hanging cave explore lawyers cave explore ledge cave explore sinkhole cave explore submerged cave explore waterfall cave explore wet cave find a new sacrifice find a way into the sinkhole\\r find and cook food\\r find live sacrifice find the missing plane passengers find the red man Find timmy Find way to climb rock walls Find way to stay underwater longer keep exploring hanging cave set up camp\\r set up defenses\\r TEMPORARY SHELTER TODO TO DO LIST TOWER DEADFALL TRAP NOOSE TRAP TRAPS TRAPS AND DEFENSE SMALL TRAPS ADVANCED TRAPS DEFENSE HAPPY BIRTHDAY TRAP ROPE SWING TRAP TREE BRIDGE TREE HOUSE TREE PLATFORM TREE SAP COLLECTOR TREE ZIPLINE TV UTILITY UTILITY 1 UTILITY 2 CUSTOM WALLS WATER COLLECTOR WEAPON RACK EXPLOSIVES WIRE TRAP MOLOTOV WIRE TRAP WOOD BENCH FREE STANDING ZIP-LINE Burnt Daily calories: Eaten MOLOTOV WIFE 2. PRESS TO ADD ITEMS TO CRAFTING AREA 3. PRESS \\n\\n\\nTO CRAFT ITEM 1. PRESS\\n\\n\\nTO OPEN YOUR INVENTORY THIS IS YOUR CRAFTING MAT YOU CAN VIEW\\nRECIPES BY HOVERING \\nOVER THE COG AFTER \\nADDING AN ITEM ALL Search by name... FRIENDS SEARCH EDIT FIELD\" "; let substitution = "${prefix}<color=#${code}>${suffix}</color>"; // result will be a String with the substituted value let result = regex.replace_all(string, substitution); println!("{}", 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 Rust, please visit: https://docs.rs/regex/latest/regex/