summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-11 21:56:42 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-11 23:25:28 +0900
commita468213917b793c47d98e172b2f0a3853460c367 (patch)
tree11e22c0c4e594b75861ab51a0555797018876f09
parentac8cf010bc2cad78f4e2cf182c475effdb12b181 (diff)
[DOC] Mention the conditional regexp
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7103
-rw-r--r--doc/regexp.rdoc9
1 files changed, 9 insertions, 0 deletions
diff --git a/doc/regexp.rdoc b/doc/regexp.rdoc
index 92c7ecf66e..c6c983d1d9 100644
--- a/doc/regexp.rdoc
+++ b/doc/regexp.rdoc
@@ -405,6 +405,15 @@ a single one that matches any of the expressions. Each expression is an
/\w(and|or)\w/.match("furandi") #=> #<MatchData "randi" 1:"and">
/\w(and|or)\w/.match("dissemblance") #=> nil
+== Condition
+
+The <tt>(?(</tt><i>cond</><tt>)</tt><i>yes</i><tt>|</tt><i>no</i><tt>)</tt>
+syntax matches _yes_ part if _cond_ is captured, otherwise matches _no_ part.
+In the case _no_ part is empty, also <tt>|</tt> can be omitted.
+
+The _cond_ may be a backreference number or a captured name. A backreference
+number is an absolute position, but can not be a relative position.
+
== Character Properties
The <tt>\p{}</tt> construct matches characters with the named property,