列出正则表达式匹配的所有模式 [英] Listing all patterns that a regex matches

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

问题描述

我正在寻找一种方法来从有限正则表达式中列出所有可能的模式(没有重复).有资源吗?

I am looking for a way to list all possible patterns from a finite regex (with no duplicates). Is there any source available?

推荐答案

虽然它不会涵盖一些高级功能,并且有自己的其他警告,Regexp::Genex 似乎与您要寻找的很接近.

Although it won't cover some advanced features, and has its own share of other caveats, Regexp::Genex seems to be close to what you are looking for.

还有 PerlMonks 的这个线程,它足够相关(以及解释如何Regexp::Genex 可能不适合你,还有一些自己动手的替代品).

There's also this thread of PerlMonks which is relevant enough (as well as explaining how Regexp::Genex might not do for you, and some roll-yourself alternatives).

否则,根据 Jeffrey Friedl 的 掌握正则表达式,您可以使用/g 修饰符,耦合使用 (?{CODE}) 扩展名和 永远不会匹配的模式,ala:

Otherwise, as per Jeffrey Friedl's Mastering Regular Expressions, you could use the /g modifier, coupled with the (?{CODE}) extension and a pattern that will never match, ala:

perl -E '$_ = 'Mastering Regular Expressions'; /(\p{L}*)(?{ say qq![$^N]! })(?!)/g;'

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

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