An overview of Regular Expressions (a way to search for patterns in text in a programming language) from my perspective and experience.
Regular Expressions are a super power.
Regular expressions 1 are a way for someone to give a programming language a pattern to search for in text.
As a programmer I find myself using them fairly frequently.
A Slack channel URL is made up of:
An example URL might look like:
I want to extract "curious" and "C019PPFA2BV" (and be able to do it regardless of what the values are).
This is where regular expressions shine.
A regular expression to match this pattern would look like this:
I won't get into the pattern itself, but you can see that it looks similar to the URL pattern we want to match (you can see "slack.com" and "archives").
There are also two sets of parenthesis
(). These are called capture groups. A capture group captures whatever content matches that part of the regular expression and returns it as a group.
This regular expression, based on the URL, will find one Match and two Groups:
As you can imagine, this means you could build an application with infinite permutations and always have one way to define the pattern you're looking for and any values you want to extract from the permutation.
Also called "RegEx" ↩
Hey, I'm Chase. I help aspiring entrepreneurs and makers turn their ideas into digital products and apps.
Subscribe to my Newsletter
Every other week I publish the Curiously Crafted newsletter.
In it, I explore the intersection of curiosity and craft: the people who make stuff, what they make and the way they pursue the craft of making.
On The Web
See all of the places I have a presence on the web.