Ruby是否支持条件正则表达式 [英] Does Ruby support conditional regular expressions
问题描述
只是一个语言功能问题,我知道有很多方法可以在正则表达式之外(或具有多个正则表达式)进行操作。
Just a language feature question, I know there's plenty of ways to do this outside of regexes (or with multiple regexes).
红宝石支持条件正则表达式?基本上,是一个正则表达式中的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屋!