This article is the official HTML5 training course for h5edu institutions, mainly introduces: JavaScript intensive Tutorial--Regular expression backtracking
The following example shows the process of processing a regular expression:
/h (ello|appy) hippo/.test ("Hello there,happy hippo");
This regular expression "Hello Hippo" or "Happy Hippo". At the beginning of the matching process, an H is first found, and the first letter of the target string is exactly H, and is immediately located. Next, the subexpression (ello|appy) provides two processing options, the regular expression selects the leftmost option (the selection always goes from left to right), checks whether the Ello matches the next character in the string, matches successfully, and the regular expression matches the subsequent spaces. Because the h in Hippo cannot match T in the next string, the match cannot continue. At this point, the regular expression cannot be discarded, because it is not yet complete with all the options in the city, and then he goes back to the nearest decision point (matching the position behind the first character H) and tries to match the second branch. The match does not succeed, and there are no more options, so the regular expression believes that the first character of the string match is unsuccessful, so start again with the second character. He did not find H, so he continued the search to know that the position of the 14th string was matched to H in "happy" and then again into the branching process, which failed to match Ello this time, but after backtracking and attempting the second branching procedure, the entire string "Happy Hippo" was matched.
The match was successful.
Click to enter JavaScript Intensive tutorial: http://www.h5edu.cn/htm/step/h5edu_44.html
JavaScript Intensive Tutorial--Regular expression backtracking