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
  • 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

/
/
mig

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"\$\s?(\d+[\.\s,\dk]+)|(\d+[\.\s,\dk]+)\$"; string input = @"I know most of you don't know me but i've been a member with a strong presence on m5board for about 5 years now. Username there is the same as here: CarbonHan History: I've owned the car since it had 64k miles on it and purchased it from a fellow enthusiast from this board. I also purchased an aftermarket warranty for the car that was effective until the car had 114k miles (roughly 2 years ago). I replaced everything and anything that i could within that time frame. Unfortunately for my wallet, the only thing I needed the warranty for was one bad cps sensor and a bad coil pack. The car has been maintained by the same mechanic the previous owner used: Qais at Southbay Autohaus. Here's his website:South Bay Hautohaus Call him and ask about my car. He'll tell you a funny story about how he refused to change out my rod bearings because he said I would be wasting my money haha Specs: 144k miles 2002 Carbon Black E39 M5 Exclusive(Luxury) interior package(extended black leather) with Bruyere Wood Trim Alcantara anthracite headliner Rear fold down seats with ski pass M-Audio Factory rear spoiler delete It has all options minus the PDC and window/rear shades You can look up some of the specs here:BMW Baureihenarchiv - BMW Vehicle Identification Number (VIN) | bmwarchiv.de Last 7 digits of my vin: CF90317Here's the bad first: 1)Car was rear ended 4 years ago in bumper to bumper traffic. Girl behind me was reaching for her inhaler and let go of the brakes. Very minor damage to the trunk and rear bumper. Had them both replaced and painted here: C&C Collision, Auto Body Repair Shop - Home (Squeaky clean Carfax) 2) The power steering pulley slightly squeals during warm up 3) The plastic piece that goes underneath the right corner of the front bumper is cracked 4) I'm missing the latch that covers the oil drain plug 5) The 2 plastic pieces that go along the firewall inside of the engine bay are cracked 6) My fold up mirrors ""work"" 7) Door seals creak or at least i think they are. They just haven't been replaced before so i'm assuming. 8) Center console armrest leather is fading 9) Driver side seat bolster leather is fading 10) I'm pretty sure I have 1 door ding somewhere 11) Rear view mirror has a bubble - NOT LEAKING Mods: BC 8/6k Coilovers with updated koyo bearings Dinan Front strut bar Dinan rear sway bar Beast power sway bar brackets with polyurethane inserts Stoptech slotted rotors w/ pagid pads 19x10 ESM LM rep wheels +15 offset Square set up on Hk Ventus v12 275/30/35/19 Predator39 Clear cornered headlights w/ 6k bulbs Orion v2 6k Angel eyes Muffler delete E60 SSk Shorty clutch stop DICE iPod integration kit Huper Optik Ceramic tint 40% Black Bimmian kidney grills Custom Jailbreak Tune hybrid Alpha-N ~352.36/340.57 WHP/TQ (SAP SES light delete, De-limited, STOCK redline, Sport mode memory) Maintenance: ALL OEM NO LEAKS WHATSOEVER/ DOESN'T DRINK A DROP OF OIL When i went to go get my car dyno tuned Matt told me that my car was the first and only car not to leave any sort of residue on the ground I've use Castrol TWS since day one until my MOST recent oil change 2k miles ago. I used LiquiMoly 10w60 NO DEAD PIXELS Battery ~ @115k miles Spark plugs ~ @90k miles Coil packs ~ @90k miles 4 CPS ~ 6k miles ago 2 TPS ~ 6k miles ago 2 MAFs ~ 8k miles ago Thermostat ~ 15k miles ago Fan Clutch & fan ~ 15k miles ago Oil separators ~ 15k miles ago All the temp sensors ~ 15k miles ago Radiator flush ~ 15k miles ago Valve cover gaskets and accessories ~ 10k miles ago motor mounts tranny mounts Diff and tranny fluids with royal purple synchromesh and mobil1 ~ 10k miles ago Replaced all known hot spots for vacuum leaks Clutch, flywheel, guibo, levers, RMS and all accessories ~ 10k miles ago Driveshaft ~ less than 1k miles ago Thrust arms ~ 3k miles ago Tie rod ends ~ 3k miles ago fuel pump ~ 20k miles ago fuel filter x2 ~ most recently 5k miles ago Fuel pump relay ~ 10k miles ago air filters ~ 7k miles ago oil filter housing rubber mounts ~ 10k miles ago all 4 o2 sensors ~ 10k miles ago Chain tensioner ~ 10k miles ago Re conditioned Vanos solenoids (o-rings,gaskets, soldering etc) ~ 10k miles ago Oil pan drain plug will NEVER EVER EVER EVER STRIP MUAHHAHA ~ 2k miles ago All new power steering hoses ~ 10k miles ago All pulleys and tensioners except for the power steering pump pulley ~ 10k miles ago Serpentine Belt and accessory belt ~ 10k miles ago I never had the SAP SES light but i had it deactivated with the tune Added: Brand new rear tires and Brand new stoptech slotted/drilled rear rotors and pads I know i'm missing other things. i've replaced a lot of misc stuff I have receipts for almost everything i've just listed here. I also have all files and videos of the dyno in regards to my custom tune. Pictures: Here's a video of one of my pre-tune dyno pulls: The car has been garaged its whole life. I've spent thousands of dollars on maintenance because I sincerely thought this day would never come. No expenses were spared on the car. I love the damn thing <3 Im asking $15,500 OBO Im asking 15,400$ Im asking 15400$ Im asking $15400 Im asking 15 400$ Im asking $15 400 Im asking 15.400$ Im asking $15.400 Im asking $ 15,400 Im asking 15,400 $ Im asking 15.400 $ Im asking $ 15.400 I have the title in hand You're welcome to come test drive it but only if you have cash in hand. You won't be disappointed. You can contact me by email: han.kim318 at gmail.com"; RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx