 Alright, knowing how the regex engine works will enable you to craft a better regular expression more easily. It will help you to understand quickly why a particular regex does not do what you initially expected. This will save you a lot of guesswork and head scratching when you need to write more complex regexes. So again, let's start with our previous demo to see how regex engine works. This will always try to match as soon as is ultimately possible. This is called greediness. Okay, watch carefully on the screen now. So a regex engine executes the regex one character at a time in left to right order. This input string itself is parsed one character at a time in left to right order. Once a character is matched, it's set to be consumed from the input and the engine moves to the next input character and tries to match that against the previously matched character in the input string. Now here to make dot optional in title, I have added question mark quantifier and as soon as it encounters a quantifier, it will search forward matching as much as possible. Now say for example, if the regex doesn't match a character in input source, then it will step back a character for character until it finds a position in which it can match again and it will continue to do so until it has either found a complete match or has exhausted all possible options without finding one. Now this stepping back is called backtracking. Either way, the engine always knows its current position within the regex. Now in the regex, if the regex specifies an alternatives and if one search path fails, the engine will backtrack to match the next alternative. In the regex, an alternation contracts in simple language is called either or operation. So here we have specified the alternative. So in the name, if Mr. title is not found, then the engine will backtrack to match the next alternative. The engine also stores the backtracking position. Now here there is no match for Mr. title. So engine will move ahead and match for the next alternation. Alright, now before we go ahead, let's understand the type of regex engine. Here please note that there is no standard definition of what is regular expression engine. So basically there are two types of engine. The first is text-directed engine and the second one is regex-directed engine. Text-directed engine attempts all parts of the regex before moving to the next character of input. Thus, this engine doesn't backtrack, while in regex-directed engine, parts are attempted in left to right order as we have already seen. If the engine fails to match, then it backtracks to attempt an alternative path. Most modern engines like PCRE, eGrab etc. are regex-directed because this is the only way to implement some useful features like a lazy quantifiers and atomic grouping etc. But here the most important one is that there is one very big difference between regex-directed engine and text-directed engine. Text-directed engine will stop at the first possible match as it encounters while a POSIX-based or a text-directed engine will try to find the longest match. This does not mean that text-directed engine will always return the longest possible match just that it will try to make the first match as long as possible even if a shorter part of the string already gave a match. Let's perform one demo to understand this concept. Alright, this is another good online regex testing tool with different flavors of engine. So here I am on the PCRE tab now and you can see that I have given the input string here and here I want to match the word byte or byte scout. So for that let us write the regex like this. So as you can see here that the word byte gets matched and stop. So as I said earlier that regex-directed engine will stop at the first possible match as it encounters. Now let us see what happened in this POSIX tab. So here when I click on this button so as you can see here that now this time we get a different result. So this POSIX engine or text-directed engine will always return the longest possible match even if a shorter part of the string already gave a match. Alright now let us move ahead. When a regular expression were first made available in the computing they only supported a very limited number of syntaxes but as things go in time people wanted to be able to match more complex patterns. So they started expanding and started to add more advanced features and syntaxes and hence they built their own regex library or engine with their own syntax variation. The reality today is that according to Wikipedia there are more than 25 different regex engine which are widely used and they all have their own regex dialects. Now one last note before we go ahead. Because there are such a variety of regex engines you should keep your preferred environment in mind when you select a tool for testing your regular expression. As I said earlier that throughout this course we will be using either a byte scout PDF multi-tool or some other online tools to give you some basic idea and understanding of fundamentals. So now you know all that. Let's dive into deeper to look in more detail at the basics and syntaxes and elements of regular expression.