寻找正则表达式的正则表达式? [英] Regular expression for finding a regular expression?

查看:174
本文介绍了寻找正则表达式的正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人有找到包含正则表达式的文件的代码吗?我假设你可以有两种不同的风格,一种用于BRE,一种用于EREs。

你会认为某种测试套件会有类似于isRegex()测试。任何人都可以有任何代码?



我看到这是讨论这里,但没有看到任何实际的回应。如果我想grep for任何包含正则表达式的文件,或许以典型的//为界限,我该怎么做?

解决方案

正则表达式本身不是常规语言。线索是它们包含括号和方括号,并且必须是平衡的。

正则表达式本身可以用上下文无关语法,并使用递归下降语法分析器进行分析。


Does anyone have code for finding a file that contains a regular expression? I would assume you could have two different flavors, one for BREs and one for EREs.

You would think some kind of test suites would have something like an isRegex() test. Can anyone have any code? Looking for something comprehensive of course.

I see this was discussed here but didn't see any practical responses. If I want to grep for any file that contains a regular expression, perhaps bounded by the typical //, how would I do it?

解决方案

Regular expressions are themselves not a regular language. The clue is that they contain parentheses and square brackets and such that must be balanced.

A regular expression itself can be described by a context-free grammar, and parsed with a recursive-descent parser.

这篇关于寻找正则表达式的正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆