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

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

问题描述

有没有人有查找包含正则表达式的文件的代码?我假设您可以有两种不同的口味,一种用于 BRE,一种用于 ERE.

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.

您会认为某种测试套件会包含类似于 isRegex() 测试的内容.任何人都可以有任何代码吗?当然要寻找全面的东西.

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.

我看到在这里讨论了这个问题,但没有看到任何实用的回应.如果我想对包含正则表达式的任何文件进行 grep,可能以典型的//为边界,我该怎么做?

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天全站免登陆