A regular expression (regular expression called regex) is a tool that is invented to solve a particular type of problem and is a string used to match and manipulate text.
the core of a regular expression is the way the regular expression engine is processed.
The general regular expression engine is divided into two types: NFA and DFA.
But the NFA has two more branches: traditional NFA and POSIX NFA the following are the supported engines in various languages:
traditional NFA: GNU Emacs, Java, grep, less, more,. NET, Perl, PHP, Python, Ruby, sed, etc.
DFA: awk, Egrep, Flex, MySQL, Procmail
POSIX NFA: Mawk, Mortice Kern, and more.
DFA/NFA hybrid engine : GNU awk, GNU Grep/egrep, TCL
The general DFA is faster, and the NFA has strong control capability.
The DFA engine does not require backtracking, so the match is fast, but the capturing group is not supported, so it does not support reverse referencing and the use of this method of referencing.
Most languages and tools use the traditional NFA engine, which has some features that are not supported by DFA:
Capturing groups, reverse references, and the method of referencing in the same way;
Surround (Lookaround, <= ...), (?<!...), (? = ...), (?! ...), or some an article called pre-search;
Ignore optimization quantifiers (??、 *, +, {m,n}, {m,}?), or some articles called non-greedy patterns;
Occupy the priority quantifiers (? +, *+, + +, {m,n}+, {m,}+, currently only Java and pcre support), curing group (...).
two. Regular processing has roughly four steps
First: Compile, when you create a regular Object Browser will convert it into a native code to perform matching work
Second: Set the starting position. When the regular class enters the practical state, first determine the starting search location of the target string
Third: match each regular expression character. Once the regular expression knows where to start, he checks the text and the regular expression pattern one at a- When a particular character match fails, the regular tries to go back to where it was before trying to match, and then try the other possible paths
IV: Announce a match success or failure