In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how the regular expression engine works internally. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Understand the need for a regular expression engine:
Knowing how the regular expression engine works helps you quickly understand why a regular expression doesn't work as you expect.
Types of regular expression engines:
There are two types of engines: text oriented (text-directed) engines and regular oriented (regex-directed) engines. Jeffrey Friedl calls them DFA and NFA engines. This article is about regular-oriented engines. This is because some very useful features, such as "lazy" quantifiers (lazy quantifiers) and backreferences (backreferences), can only be implemented in regular-oriented engines. So it's not surprising that this kind of engine is the current engine.
You can easily tell whether the engine you are using is text-oriented or regular-oriented. If backreferences or "lazy" quantifiers are implemented, you can be sure that the engine you are using is regular-oriented. You can do the following test: apply regular expressions to the string "regex not". If the result of the match is regex, the engine is regular-oriented. If the result is regex not, it is text-oriented. Because the regular-oriented engine is "urgent", it will be eager to show its work and report the matches it finds.
A small summary of the regular expression engine:
Regular-oriented engines always return the leftmost match, which is an important point to understand: even if it is possible to find a "better" match in the future, regular-oriented engines always return the leftmost match.
When applied to "He captured a catfish for his cat", the engine first compared to "H" and failed. So the engine failed to compare it with "e". Until the fourth character matches "c". Matches the fifth character. To the sixth character failed to match "p", also failed. The engine continues to re-check the match from the fifth character. Until the fifteenth character starts and matches the "cat" in "catfish", the regular expression engine eagerly returns * matches instead of looking for other better matches.
Thank you for reading! This is the end of this article on "what is the internal working mechanism of the regular expression engine". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.