Ruby 是否支持条件正则表达式 [英] Does Ruby support conditional regular expressions

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

问题描述

只是一个语言功能问题,我知道在正则表达式(或多个正则表达式)之外有很多方法可以做到这一点.

Just a language feature question, I know there's plenty of ways to do this outside of regexes (or with multiple regexes).

ruby 是否支持 条件正则表达式?基本上,正则表达式中的 IF-THEN-ELSE 分支,其中 IF 的谓词是表达式中捕获的组的存在(或不存在).

Does ruby support conditional regular expressions? Basically, an IF-THEN-ELSE branch inside a regular expression, where the predicate for the IF is the presence (or absense) of a captured group in the expression.

在 perl 中,语法是 (?(predicate)yes-pattern|no-pattern)

In perl, the syntax is (?(predicate)yes-pattern|no-pattern) as in

/(?:y|(x))(?(1)y|x)/

我无法在我浏览过的任何 ruby​​ 文档中找到任何类似内容的参考,但我想我会在这里询问以确保,以防我搜索错误的单词,或者它已从文档中删除.

I haven't been able to find any reference to anything like it in any ruby docs that I've browsed, but I figured I'd ask here to make sure, in case I was searching for the wrong words, or it was elided from the docs.

推荐答案

不,ruby 不支持(1.8 和 1.9 都不支持).

No, ruby does not support that (neither in 1.8 nor 1.9).

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

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