简体   繁体   English

RegexBuddy中的“步骤”是什么?

[英]What are “steps” in RegexBuddy?

RegexBuddy on the tab "Debug" shows how regular expressions are executed step by step. “调试”选项卡上的RegexBuddy显示了如何逐步执行正则表达式。 But what exactly that steps mean? 但是这些步骤到底意味着什么? What operations are behind every step? 每个步骤背后都需要进行哪些操作?

The steps count is basically how many times the current position in the input was changed, which is a very good indicator of performance. 步数基本上是更改输入中当前位置的次数,这是性能的很好指标。

The "current position" may be at any character or between characters (including before and after the entire input). “当前位置”可以任何字符处或字符之间 (包括整个输入之前和之后)。

Simplifying it, regex engines process the input by moving the current position along the input and evaluating whether the regex matches at that position. 为简化起见,正则表达式引擎通过沿输入移动当前位置并评估正则表达式在该位置是否匹配来处理输入。 They also keep track of the position in the regex the match is up to. 他们还跟踪比赛中正则表达式中的位置。

I don't want to turn this answer into a regex tutorial, but... regex engines always consume as much of the input as possible while still matching. 我不想把这个答案变成一个regex教程,但是... regex引擎在匹配时总是消耗尽可能多的输入。 To give a simple example, given the input "12345" and the regex .*1.* , the regex engine will first apply .* consuming all input leaving the position at the end of the input, fail to match a 1 , then back track by "uncomsuming" one character at a time until it finds a 1 , then continue. 举一个简单的例子,给定输入"12345"和正则表达式.*1.* ,正则表达式引擎将首先应用.*消耗所有输入,而将位置保留在输入的末尾,不匹配1 ,然后返回通过一次“不消耗”一个字符来跟踪 ,直到找到1 ,然后继续。 You can see that this would take 9 steps just to process the initial .* . 您会看到这仅需要9个步骤即可处理初始.*

By contrast, if the regex was [^1]*1.* , the regex will match the "1" in just one step. 相反,如果正则表达式为[^1]*1.* ,则正则表达式将仅一步就与"1"匹配。

In RegexBuddy's debugger, a step is when the regex engine matches something, or fails to match something. 在RegexBuddy的调试器中,步骤是当regex引擎匹配某项或匹配某项失败。 Steps that match a character are indicated by all the characters matched by the regex so far which will usually be one character more than the previous step. 到目前为止,与某个字符匹配的步骤由正则表达式匹配的所有字符表示,通常比上一步多一个字符。 Steps that match a position, like a word boundary, are indicated by the characters matched so far plus "ok". 到目前为止,已匹配的字符加上“ ok”表示与某个位置(如单词边界)相匹配的步骤。 Steps that failed to match something are indicated by the characters matched so far plus "backtrack". 到目前为止,匹配的字符加上“ backtrack”指示了未能匹配某些内容的步骤。

If you click on any of the matched characters in the debugger, RegexBuddy selects the token in the regular expression that matched those characters and highlights all the characters in the debugger matched by that token. 如果在调试器中单击任何匹配的字符,则RegexBuddy在正则表达式中选择与那些字符匹配的标记,并突出显示调试器中与该标记匹配的所有字符。 If you click on an "ok" or "backtrack" indicator, RegexBuddy selects the token in the regex that matched or failed to match. 如果单击“确定”或“回溯”指示器,则RegexBuddy会选择正则表达式中匹配或不匹配的令牌。

Moving the cursor with the keyboard has the same effect as clicking. 使用键盘移动光标与单击具有相同的效果。 Pressing the End key on the keyboard moves the cursor to the end of a step. 按下键盘上的End键将光标移至步骤的结尾。 Then pressing Arrow Up or Down moves the cursor to the previous or next step while keeping the cursor at the end of that step. 然后,按向上或向下箭头,将光标移至上一个或下一个步骤,同时将光标保持在该步骤的末尾。 By moving the cursor this way, you can easily follow how the regex engine steps through your regular expression and which characters is matches and backtracks along the way. 通过以这种方式移动光标,您可以轻松地了解正则表达式引擎如何逐步执行正则表达式以及该过程中哪些字符是匹配项和回溯项。

For more details, see these two pages in RegexBuddy's help file: https://www.regexbuddy.com/manual.html#debug https://www.regexbuddy.com/manual.html#benchmark 有关更多详细信息,请参见RegexBuddy帮助文件中的以下两个页面: https : //www.regexbuddy.com/manual.html#debug https://www.regexbuddy.com/manual.html#benchmark

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM