Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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
No Match

r"
"
gm

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"\(\s?[Rr]ead(.*?)\s(time)\:?(.*?)[1-9](s*)(.*?)\)" test_str = ("(Readin' time: 1m 14s) When I was verifying that the quote \"What doesn't kill me makes me stronger\" did indeed come from Frederich Nietzsche (apparently it does), I learned that Kelly Clarkson used that quote her pop song \"Stronger\". Or, whoever wrote the song used the Nietzsche quote. I wondeor me too. Happy (Easter, if you're in Greece) Sunday, -P\n" "(Readin' time: 16 seconds) A while back I wrote about the \"Sea Change Home Page\". The following, from Expertise Incubator member Bob Lalasz, is an excellent piece with more, better information on that same idea: scienceplusstory.com/we-might-be-doing-it-all-wrong/ What sea change do your services help clients deal with? Happy Saturday, -P\n" "(Readin' time: 2m 43s) \"Boney's high on china white, Shorty found a punk. Don't you know there ain't no devil, there's just God when he's drunk. Well this stuff will probably kill you, let's do another line. What you say you meet me down on Hedestruction in other industries. People in Industry X lose jobs because of automation, for example, and the sense is that the Tech Industry exported a destructive force (seen from the perspective of thnly, you'll struggle to see the deeper value of specialization an the 14th century BCE. That's a long time! In the tech industry you see these creation-destruction-recreation cycles happen quickly enough that they're easily visible. Mainframes -> microcomputers -> \n" "(Readin' time: 1m 23s) I want to see if this LinkedIn lead generation approach described here works well for others. So I'm putting together a free online workshop to test this. It'll be free only in the sense you won't pay me for it. You'll need to do a fair bit of tends to win out connects/day done, conversations nurtured 6: Repeat above 7: Repeat 8: Repeat That application link again: forms.gle/7j6rFkUjbKXr2skC6 -P\n" "(Readin' time: 1m 48s) While in Sebastopol for the move, I went to a new coffee shop a few times. It's called ACRE, their product is wonderful and seemingly ethically produced, and you can order beans pouring-water part of the pourover process, and it works quite well. don't have all the context here, but knowing what we know: is this the best investment they could have put $12,500 towards? -P\n" "(Readin' time: 1m 47s) List member Josh Earl said something really crucial in response to my SPoF email. Josh graciously gave me h out for in validating an idea. Consider signing up for Josh' email list: joshuaearl.com It's great stuff. -P\n" "(Readin' time: 33 seconds) This is interesting: www.cnbc.com/2019/04/26/the-15-us-jobs-disappearing-the-fastest.html Not every one of these 15 entries describes the main reason why that job is one of the fastest disappearing, but it's obvious. In every case, it's changes in technology and automation. As my friend \n" "(Readin' time: 1m 17s) \"And mad boy grips the microphone, with a fistful of steel! With a fistful of steel! ('Cause I know the power of the question!) With a fistful of steel! With a fistful of steel! (And I won't stop, 'cause I know the power of the question!)\" -- \n" "(Readin' time: 5m 25s) I got a late start with writing today, but let's see if I can wrap up this podcasting series anyway. I want to touch on a few final points, including: Seasons or ongoing or miniseries? Publication questions: frequency, scheduling, etc. podcast and it'll just live at that URL until further notice. The idea for a podcast that promotes a specific service or product (rather than just being lead gen or trust building or deepening your connection with your audience) is an idea I lifted from Brian Clark. A few years ago, he created this really interesting podcast for the launch of his rainmaker.fm hosting company. The podcast explained the worldview his new product related to, and this struck me as a great way to build interest and urgency around the launch of a differentiated product. I'd link you to this podcast, but I can't find it anywhere right now. Any readers got a link? A fun sidenote on the topic of quitting. This might be my favorite episode of This American Life: https://www.thisamericanlife.org/7/quitting Frequency, scheduling, etc. How frequently should you publish? Should you publish on a rigid schedule, or should you publish whenever a new episode is ready? Spoken like a true consultant: it depends! It depends on what you're trying to accomplish, and other decisions you \n" "(Readin' time: 8m 15s) Since I talked so much yesterday about structural interest, let's move onto the next related concept, which is: being a good interviewer. To be clear, you may not need to do this for your podcast. It might be a solo show, or a 2-people talking show, or something else. But a lot of business podcasts involve interviewing, and if I can die knowing I've contributed to fewer crappy business podcast interviews, I'll die a happy man. Furthermore, the core skills of being a good interviewer have moment can be really powerful. Allllrighty! I think that's a pretty solid treatment of the interviewing topic. Tomorrow I'll move on to the question of publication: how often, how to make use of seasons or miniseries, and stuff like hosting, etc. Until then, -P\n" "(Readin' time: 2m 58s) List member Mohan gave me permission to share his delightful response to this previous email about a \"consultant litmus test\": It's not a ridiculous idea. It's actually kind of easy. I'll explain by way of an anecdote. (First of all, when we say \"consultant\", I'm going to assume that you and I are both talking generation for experts, all of which seem to be the core themes of this list. Have a great weekend, y'all! -P\n" "(Readin' time: 16 minutes and 29 scintillating seconds) OK! We've talked about equipment. We'll move onto more consequential things now, after I touch on a few questions from the last email. One Q I got more than once was, \"What! Why no love for the Blue Yeti mic?\" It's not a bad mic at all. I've never used one, but I'm pretty sure ") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html