Welcome back.
In this video we'll start this chapter for regular expressions.
We'll begin by understanding what regex is and look at some basic examples.
Then we'll get into every type.
There is some challenges.
And finally how to actually use it with C sharp.
I hope this sounds good to you.
So let's get started.
Well, I'm on this website where you can check out the regular expression language with a quick reference.
And there are so many different escaped characters in order to find stuff or in order to create patterns.
And there are a lot here, and I'm going to use the most important ones of those.
I'm not going to go into every single one of them, but you will see many different examples which will
make sure that you understand regular expressions.
And then it will be super easy to go back to this side and use the other ones if you ever need them.
All right.
So let's go back into Visual Studio.
And I have created a little sample text.
So let's create a new regular expression project.
I have one here.
I'll just call it any way you want.
And let's create a new file in here as well.
New item.
And this time we're not going to create a class.
It's just going to be a very basic text file.
So here text file.
And I'm gonna call it sample dot text.
Now let's open up that sample dot text file.
And I just copied and pasted some code in there or some text in there.
And as you can see, numbers, telephone numbers, German telephone numbers and so forth.
The alphabet some la la la.
Text and so forth.
So we are going to use regular expressions in order to mark those specific patterns that we're searching
for.
And that will make a lot more sense once we get into practice.
So let's press control F or command F in order to get to the find tool here.
And once you're here, press this.
Use regular expressions or alt e so that it will use regular expressions.
Now.
Now our search console here will apply regular expressions.
So what are regular expressions.
Well you saw some of them.
Let's start with a very simple one.
So I'm going to go ahead and start with tabs.
So let's go for backslash tab.
And as you can see now tabs are marked.
So in my case I'm going to make it a little bigger so you can see it better.
Here are some tabs.
Let me create some more tabs.
As you can see now the tabs are all marked here.
They're all highlighted.
Now let's find every new line by backslash n.
So you can see this is where the new line starts.
And here as well.
So this is pretty much where I pressed enter.
Let me press some more enter.
As you can see here, each time I press enter and I break the line I have this backslash n.
So that's how I can figure out whether there was a new line or not.
So what do I get all of those backslash n and so forth from?
Well, I can find them here under the regular expression language quick reference.
But I've also created a little snippets dot text file.
So let me create a little file and I'm going to paste it in there.
You can download them from the assets of this lecture.
And I'm going to call them snippets dot text.
So here we have character escapes which are for example tabs.
So we can find out whether there are tabs in my string which is in my sample dot text file, the whole
file.
So here I'm checking for the whole file.
And I'm checking for every single new line or every single tab in my whole file.
Pretty much.
Okay.
Then we have the character classes.
For example a dot.
A simple dot is a wild card matches any single character except for backslash n, so except for new
line.
Let's check out if that's true.
So we have new lines.
Let's check it out again by using the n key here.
As you can see we get all the new lines.
Now let's use the dot and dot.
As you can see matches any single character.
So that's what this dot and or dot does.
It is a wild card.
So if you want to mark everything, well that's the way to go.
So here you can see it checks out everything it says except for the new line.
But as it seems new lines are also marked.
So each time I create a new line, it's still marked with this dot.
All right.
So let's check out the next one.
I'm going to go through some of them.
And then we'll combine them to use some cool cool things.
All right.
So matches any digital or any decimal digit.
Let's go ahead and check that out.
Backslash D standing for digit.
And as you can see my number here 1234567890 are all marked.
And here all my numbers are marked.
And the values in between for example the plus sign, the hashtag and so forth.
They're not marked okay.
So any number will be found or any number will match that pattern of this regular expression.
Backslash D, which stands for decimal backslash.
Capital D will do the opposite.
So it will take everything else but numbers.
As you can see here.
Again, if you want to have the white space you can use backslash s.
Then you get any white space that you have in your file.
So if you let's say want to get rid of any white space in your file, you could use this pattern and
get rid of everything that matches that pattern.
Capital S on the other side is everything that is not a whitespace.
So as you can see, the capital is pretty much the opposite always.
So D is all numbers.
Capital D is except numbers.
So everything except numbers.
Great.
Next we'll work on creating complex patterns and using alternation constructs.
See you in the next video.