in this video you will be learning about special sequences used write regular expression lets start with our first topic, what are special sequences special sequences sspecifies predefined classes we write these special sequences using backslash for ex: d matches decimal equivalent digits from 0-9 why do we need these special sequences? commonly used patterns can be written easily by using these special sequences, to understand these lets move on to next topic.
we will understand special sequences with example these are some of the special sequences, we will be using these sequences to write regex. lets test these using regx101 online testing tool consider i have a testing string welcome to go Getmyguru here if i want to check the string starts with welcome then what i have to? i can make use of A and give the char you want to match so what is the purpose of A it assers position at start of the string it checks whether welcome is present at the starting of the string if it is present it returns match here you can observe instead of welcome if i write other word it is not matching i hope you understood, instead of A i will give , in test string so still it is getting matched let me remove this and put at the end , we are getting match is matching if the given sequence is present at the beginning or at the end of the string now lets understand B i will give food, here if i give food in test string we are not getting match it matches if the string contains the word food but not at the beginning or end of the string i will add some text before food, now we are getting match this is for B given before the matching pattern foodB , what happens we are not getting any match, i.e because the word cannot be at the end of the string, if i give here if i add text after food ia m getting match next lets understand d if the string contains digits from 0-9, it returns match, vivan123, now it is matching because we have digits 123 i hope you are clear.
if i give D what happens? this returns match if there are no digits in the string it matches all other characters.
next lets see s in test string i will give python tutorial, yes we are getting match here and it is matching white space.
so what exactly s is doing? it matches any white space character instead of s if i give S it matches non white space characters.
next we will see w and W w, test string is vivan _123 whether we are getting match, yes we are getting match 9 matches we are getting all the characters are getting matched.
that is w matches all the alpha numeric characters and _ is also included as alphanumeric character if i give W, any match? there are no matches.
when we make use of this sequence? this sequence is used to match any non-alpha numeric characters.
suppose if i give :, now it is matching.
now lets learn, special sequence capital Z i hope you remember, A used to return a match if the word is present at the start of the string , is opposite to that.
it returns match, if the word is present at the end of the string.
regular expression will be welcome in the string i will write we welcome, we have got match, i hope all of you are clear with all thse special sequences used to write regular expression