简体   繁体   English

如何确定正则表达式实现是否使用DFA或NFA?

[英]How to figure out if a regex implementation uses DFA or NFA?

I'm facing the question, whether a certain regex implementation is based on a DFA or NFA. 我面临的问题是,某个正则表达式实现是基于DFA还是NFA。

What are the starting points for me to figure this out. 我有什么出发点来解决这个问题。 One could also ask: What am I looking for? 人们还可以问: 该找什么? What are the basic patterns and / or characteristics? 什么是基本模式和/或特征? A good and explanatory link or a little comparisons (even if not directly dedicated to regex) is perfectly fine. 一个好的和解释性的链接或一些比较(即使不直接致力于正则表达式)是完全正常的。

If it's a black box, then give it some input and measure its time characteristics with a pathological case, with reference to the graphs in this discussion of NFS vs backtracking regex implementations . 如果它是一个黑盒子,那么给它一些输入并用病理案例测量它的时间特征,参考这个讨论NFS与回溯正则表达式实现的图表。 (note the NFS graph is microseconds not seconds). (注意NFS图是微秒而不是秒)。

Also, if it's a pure NFA, then it won't have some non-regular features which are found is some 'regular expression' parsers, which require backtracking. 此外,如果它是一个纯粹的NFA,那么它将不会有一些非常规特征,这些特征是一些需要回溯的“正则表达式”解析器。

Alternatively, look at the documentation of the RxParser class; 或者,查看RxParser类的文档; documentation appears to be unavailable on the web and requires a squeak runtime to browse. 文档似乎在Web上不可用,需要一个吱吱声运行时才能浏览。

I think you mean "regex implementation" rather than algorithm (in the usual sense). 我认为你的意思是“正则表达式实现”而不是算法(通常意义上的)。

You could test with know expressions that are known to cause problems with one approach or the other. 您可以使用已知会导致一种方法或另一种方法出现问题的已知表达式进行测试。 Also looking for features that are easier to implement in one or the other (this is not a reliable approach – the developers of regex engines find new ways to implement previously hard things). 还要寻找更容易在一个或另一个中实现的功能(这不是一种可靠的方法 - 正则表达式引擎的开发人员找到了实现以前难以实现的新方法)。

Normally the answer is to read the documentation, or look in a known reference ( "Mastering Regular Expressions" documents many popular cases). 通常答案是阅读文档,或查看已知的参考文献( “掌握正则表达式”文档许多常见案例)。 Finally why not ask the authors? 最后为什么不问作者呢?

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

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