Before always think oneself is also good, in look at the times of cobalt carbonate, Barret Lee and other great gods are playing the perfect after the superb found I was only a war five slag.
To embrace the thigh, to seek the great God,
I had an impression that there were a lot of engines, but I didn't know what the engines were.
Today read "Proficient in regular expression" only to find traditional nfa,posix NFA and DFA (specific Baidu under it).
Can be used for such a long time, still do not know what kind of JS belongs to it.
In "Mastering regular Expressions" There is a simple method of detecting which one belongs.
Use /nfa|nfa not/ to match "NFA not".
If the match results are ' NFA ', then this is the traditional NFA (the traditional NFA).
If it's ' NFA not ', it could be a POSIX NFA or a DFA.
Let's try the regular first.
" NFA not ". Match (/nfa|nfa not/);
The result is the NFA, then you can be sure that JS engine is the traditional NFA.
If it is ' NFA not ', then proceed to the next test to determine whether it is a POSIX NFA or a DFA.
/x (. +) +x/ to match "==xx=============================".
If the execution time is long, the NFA (the traditional NFA can already be determined in the previous step).
If the execution time is short, the basic is the DFA, also may be the advanced optimized NFA.
In addition, if the execution of overflow, time-out, it can certainly be the NFA.
Let's try this, okay?
Console. Time ('/x (. +) +x/test '); "==xx=============================". Match (/x (. +) +x/); console. Timeend ('/x (. +) +x/test ');
/x (. +) +x/test: 17300.000ms
Oh, my God, a little regular match for 17 seconds, I scared the urine. (This result is related to the computer configuration, your God machine may be faster than I n times)
Of course, I can't explain it now, I can only tell you this seems to be the NFA engine's backtracking runaway caused.
So we can use this method to detect the NFA and the DFA.
NFA is the expression of the dominant engine, DFA is the text-driven engine, and we have learned that JS is a traditional NFA, then we will be around this NFA in-depth study.
Today's sharing is these, I will go to practice, and continue to share tomorrow.