Link Search Menu Expand Document

Module 2: Regex Engine Basics (Part 1)

Previous Tutorial - Next Tutorial

Welcome to the module-2 of this course, regular expression for beginners. Now you know what regular expressions are in this module. We will take a look in more detail at the regular expressions, basic syntax we used when we will build our first regex. We will also learn some Regex engine fundamentals.

This regular expression subject is a little bit complicated and hard to digest, and I don't want to give you an overdose of it. For the easiness of learners, I have divided this module into some parts. This is part one of module-2 and in this segment, we are going to learn about the Regular Expressions engine, how it works internally, and what are the different types of regex engines available today.

Then we will start to understand the real basic concept of Regular Expression, its engine syntax, and elements in detail, such as matching characters, what are the character classes and wild cards, etc. For demo purposes, wherever possible, we will use either PDF multi-tool, which you already know in the previous module or some online regular expression tool.

Regular Expressions is nothing but pattern recognition. Whenever you plan to use regular expressions in any of your applications, the first thing you need to do is to identify the pattern on which you want to do some operation. Let's take an example from our previous module, where we replace the title from the given name list with the empty string.

Now let's try to understand how it works. Here I define one Regex and one input source. This input source contains the list of names from which I want to find the title. Before we go ahead, let's try to understand each element used in the regex pattern through one online tool to get some idea.

This is a good online regex testing tool with a different flavor of the engine. Here, I have defined the input source on which I want to perform some operation, at least in this case, I want to find all the titles defined in this input source. Let's start to build the Regex.

Before we start writing, first identify the pattern. Here in the input source, we have the title “mister” followed by either a dot or space. In the same way, “miss” is either followed by DOT or there may be a space. I want to find this title by writing the Regex. First, let us find Mr. here, I also want to find the dot, but DOT has a special meaning in the world of Regex expression as it is a language element. We need to treat it as a little character and for that, we need to use a backslash followed by DOT.

A backslash is also called a character ESCAPE and to make the DOT optional, I need to use the Question mark character. This question mark character is called quantifiers. We will understand each language element in detail later on in this module and then there is a space. So the first pattern is ready now.

RegEx Engine

At the same time, I also want to find the other titles such as Mr. Mrs, etc. For that, I need to use here a pipe sign. This pipe sign is called an alternation construct. In simple language, this is called either OR operation means in our case, identify a pattern which either contains the title Mr or Miss or Mrs. Let us find the Mrs pattern. For that followed by Dot and space then alternation followed by Miss. Which may contain a dot or may not contain a dot, so I make it optional.

This is how it matches the pattern and highlighting all the matching elements here. Now we have Regex and the input source is ready. Next, you send both these input sources you want to test, as well as the regular expression to the Regex function.

In a real-world scenario, this input source will normally be a texturing or a group of string or database tables data or any arbitrary data for which you are using the regular expression. Once the function has received both the input source as well as the regex, it will go to the regex engine, which will compile the Regex and generate the string and return the result as output.

RegEx Engines

Depending on the Regex function used, you will either get a true or false type of result or several counts of matches or some array string with matches, which you can use further for processing.

Web API for developers Free Trial Offline SDK

Here's RegEx video tutorial:

Other useful articles:


Back to top

© , Regexsonline.com — All Rights Reserved - Terms of Use - Privacy Policy