Basics Of Regular Expressions

At these quarantine days due to Corona I thought an idea to write blog, In my group projects in the university we have used MongoDB database. In mySQL we can use wildcards when we search in the DB by using  the keyword  "LIKE", But in mongodb there is not any "LIKE" keyword. To use wildcard searches in Mongo we need to use Regular Expressions. So the today's topic I'am going to talk about is Regular Expressions.

Basically Regular Expression is a way to search through string of texts. For the demontration purposes I am using RegExr website. In there you can practice your own Regular Expressions.

You can see under the Expression bar There is /The/. The text Between the slashes is the Regular Expression. And there are also many flags available to apply after the Regular Expression.
So it will write like this. /regExp/<flag>.


By the global flag you can search all the texts which are equivalent to the regular expression. By setting this flag off will result only one text result.
By the case insensitive flag will search the text irrespective of the cases of the letters.


From the picture you can see I have enabled the g & i flags, Because of g there are two results and the because of i there are "The" and  "the" highlighted cases.

Special Characters of Regular Expressions

Example for the + 


This will match 1 or more of the preceding token which is "T". 

Example for the *



In this example the expression matches for "a" and 0 or more occurrences of "e"s. So that is why the "with" highlighted because there are not any "e" after h. But if we use + instead of * then "with" will not get highlighted.

Example for the + 

+ means optional. In this example the expression matches for "h" then the word get highlighted and also if the expression matches for "h" and "e" then it will get highlighted. So we can see by using the + we can create optional character for the search.

Comments