While there are many implementations of regular expressions that differ sometimes slightly and sometimes significantly in syntax(语法) and behavior, there are basically only two kinds of regular expression engines: text-directed engines, and regex-directed engines. Nearly all modern regex flavors are based on regex-directed engines. This is because certain very useful features, such as lazy quantifiers and backreferences, can only be implemented in regex-directed engines.
译文:
虽然有许多实现的正则表达式语法和行为有时略有不同,有时显着,基本上有正则表达式引擎只有两种:文本导向引擎,和正则表达式导向的引擎。几乎所有现代的正则表达式是基于正则表达式引擎。这是因为一些非常有用的功能,如量词和反向引用,只能在正则表达式的正则导向中实现。
A regex-directed engine walks through the regex, attempting to match the next token in the regex to the next character. If a match is found, the engine advances through the regex and the subject string. If a token fails to match, the engine backtracks to a previous position in the regex and the subject string where it can try a different path through the regex. This tutorial will talk a lot more about backtracking later on. Moderns regex flavors using regex-directed engines have lots of features such as atomic grouping and possessive quantifiers that allow you to control this backtracking.
遍历一个regex正则导向的正则表达式,试图匹配正则表达式中的下一个标记到下一个字符。如果找到一个匹配,引擎通过正则表达式和目标字符串的进步。如果令牌不匹配,引擎回溯到以前的位置在正则表达式的目标字符串中通过正则表达式,它可以尝试不同的路径。本教程将多谈了很多,关于回溯稍后。现代人正则表达式使用正则表达式定向引擎的口味有很多的功能,例如,使您可以控制这种回溯的原子分组和占有优先量词。
A text-directed engine walks through the subject string, attempting all permutations of the regex before advancing to the next character in the string. A text-directed engine never backtracks. Thus, there isn't much to discuss about the matching process of a text-directed engine. In most cases, a text-directed engine finds the same matches as a regex-directed engine.
文本导向的引擎走过的主题串,试图推进到下一个字符串中的字符前的正则表达式的所有排列。文本导向的引擎不会回溯。因此,没有太多的讨论文本定向引擎的匹配过程。在大多数情况下,文本引擎找到相同的匹配一个正则表达式定向发动机。
When this tutorial talks about regex engine internals, the discussion assumes a regex-directed engine. It only mentions text-directed engines in situations where they find different matches. And that only really happens when your regex uses alternation with two alternatives that can match at the same position.
当本教程中有关正则表达式引擎内部,讨论假设一个正则导向引擎。只提及文本引擎的情况下,他们发现不同的匹配。只有真正发生时,你的正则表达式使用交替有两种选择,可以在相同的位置相匹配。
有一点非常重要:一个正则表达式引擎总是返回最左边的匹配,即使后来发现一个“更好”的匹配存在。当施加一个正则表达式字符串时,发动机启动的第一个字符的字符串。它会尝试所有可能的排列的正则表达式的第一个字符。