---
title: 'Finally Understand Regular Expressions - In Just 7 Minutes!'
source: 'https://youtube.com/watch?v=IzBk58Eorr4'
video_id: 'IzBk58Eorr4'
date: 2026-08-02
duration_sec: 446
---

# Finally Understand Regular Expressions - In Just 7 Minutes!

> Source: [Finally Understand Regular Expressions - In Just 7 Minutes!](https://youtube.com/watch?v=IzBk58Eorr4)

## Summary

This video provides a concise introduction to regular expressions, covering core concepts such as character classes, quantifiers, character ranges, capturing groups, and lookaheads/lookbehinds. The presenter uses the regexr.com website for live demonstrations, making it easy to follow along.

### Key Points

- **Introduction to Regular Expressions** [00:00] — Regular expressions are used for matching text patterns and validating string formats. The video uses regexr.com for examples.
- **Character Classes: \w, \d, \s** [00:42] — \w matches any alphanumeric character, \d matches digits, and \s matches whitespace (spaces, tabs, newlines). Uppercase versions (\W, \D, \S) match the negation.
- **The Dot and Quantifiers** [01:53] — The dot (.) matches any character except newline. Quantifiers: * (zero or more), + (one or more), ? (zero or one), and curly braces {m,n} for specific ranges.
- **Character Ranges** [03:03] — Square brackets define character sets, e.g., [cs] matches 'c' or 's'. Ranges like [a-p] match any letter from 'a' to 'p'. Negation with ^ inside brackets.
- **Capturing Groups** [03:45] — Parentheses create capturing groups. Example: extracting domain from email addresses using (\w+)\.(\w+).
- **Lookaheads and Lookbehinds** [05:13] — Positive lookahead (?=...) matches if followed by pattern; negative lookahead (?!...) matches if not followed. Lookbehinds (?<=...) and (?<!...) work backwards.
- **Combining Patterns** [06:45] — Multiple patterns can be combined in one expression, but for readability it's recommended to split complex expressions.

### Conclusion

Regular expressions are a powerful tool for text processing, and this video covers the essential building blocks: character classes, quantifiers, ranges, groups, and lookarounds. With practice, you can apply these to real-world tasks like email validation and file matching.

## Transcript

Today we are going to have a look at regular expressions We are going to look at matching how to do captures Regular expressions are used for a lot of things, such as grabbing
a bit of text from a string, validating that a string is in the right format Now I'm going to be using a really useful website called regexr if you're interested and want to follow along.
I've been searching for Cat. but obviously that's not what makes it powerful. you can use here to help you with your searches.
anything that starts with a letter or a number. So with \w, it will match every alphanumeric character
as well as things where we've got a three here as well is matching. So here we can see we've just got this 3at thats matching at the bottom.
So this will match spaces as well as tabs and new lines. So we haven't got anything here that starts with a space and an at. So here we can see we're matching each of the spaces with an a
and it will also matching whether a is preceded by a new line. Now these three W, D and S also have the negative versions as well. So if you wanted to search for everything, that's not a letter or a number,
So here we can see it's matching just the spaces. Or we can do not a space with a capital S You can see here that that at here with the number isn't matching.
that is used to match any character in your string, and that is a dot. we can see we're matching everything apart from new lines here. one character followed by dots, but say you don't care
how many characters you have beforehand, you just want everything ending in an a. So here we can do a .* which matches zero or more characters. There's also a + which matches at least one character.
So you see here is very similar but it’s matching at least one. So if we had A on a new line, it would also match that as well. So here we can see
we're matching three a’s because we've got this question mark here. we can use a curly brace in here, If we had in a few more a’s in here.
So we've got another four here and then another five. If you wanted to match all of these, then you can also do a comma five, to match everything where there's an a in the range from 3 to 5 of them.
In regex it's also possible to put in a range of characters to match for. we can see here we're matching on cat, sat, mat but say we only want to match it if it starts with a C or an S Here
we can put in square brackets this time and C and S and then close bracket. You can also include ranges as well. Say we only want to match from things that range from letters A to P,
you can see here that we are also matching cat, mat but we're not matching on sat. So say we don't want to match anything and therefore we only match on everything that's not in A - P.
But what if you want to extract So let's say we're interested in email addresses, but we only want the domain of those email addresses.
So in this case, I'm just going to do a \w to find everything before my @ symbol. for email addresses that caters for every single type of email address. So this is where we put a star in, and then we want an @ symbol to say
Then we're going to do another \w with a star to say, give us everything after the symbol and then we're going to do a dot. we actually want an actual dot, so we need to escape it with a backslash
and then we do another \w to end in our dot com with a star. So here you can see it has matched that email address nicely. So to do this we add in brackets around the bit
If we go to details on here, we can see that we have a new group and the group matches our domain names. So let's say we're going to split out the domain extension
And then another one after the dot to match that as well. one for the name of the domain and the other one for the extension.
If you need to match a load of file names, You can do that with regular expressions. that people find particularly confusing is positive and negative
Whenever you want to match something that's when you use these positive and negative look aheads. So here we're matching on every single a.
Say you only want an A if it's followed by a T here, you can put in bracket followed by question mark then equals T, and that gives us a positive look ahead. But let's say we want the opposite.
This is what we call a negative look ahead. And to do that, we just replace that equal sign with an exclamation mark. all of the occurrences where they have an a isn't followed by t.
but instead we're just looking backwards instead of forwards. So here we want to see all of the A's preceded by a space So to do this we do open bracket question mark again,
but this time we need to add in an arrow to say we're looking backwards. Then equals and then we'll do our \s for our new line character. so we've got an eight here because there's a space before it.
but we're not matching any A's that are in the middle of a word. look behind, you just need to replace that equals with an exclamation mark.
And now you can see here we've got all the A's, all preceded by a space. So it's possible to do multiple searches in one regular expression. preceded by an S as well as all the T’s.
and then add in a T and you can see here we're also matching the T’s. if you're going to be chaining on lots of different expressions. then I recommend that you split these out
If you like this one, then you might like this one on Stack and Heap Memory. Thank you for watching and I'll see you in the next video.
