Ruby 是否支持条件正则表达式

Does Ruby support conditional regular expressions(Ruby 是否支持条件正则表达式)
本文介绍了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 是否支持条件正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)