@@ -94,6 +94,32 @@ p $~.begin(4) # => `begin': index 4 out of matches (IndexError)
9494
9595- ** SEE** [ m: MatchData #end]
9696
97+ ### def begin(name) -> Integer | nil
98+
99+ name という名前付きグループの部分文字列先頭のオフセットを返します。
100+
101+ name の名前付きグループがマッチしていなければ nil を返します。
102+
103+ - ** param** ` name ` -- 名前(シンボルか文字列)
104+
105+ - ** raise** ` IndexError ` -- 正規表現中で定義されていない name を指定した場合に発生します。
106+
107+ ``` ruby title="例"
108+ /(?<year>\d {4} ) 年(?<month>\d {1,2} ) 月(?:(?<day>\d {1,2} ) 日) ?/ =~ " 2021年1月"
109+ p $~ .begin(' year' ) # => 0
110+ p $~ .begin(:year ) # => 0
111+ p $~ .begin(' month' ) # => 5
112+ p $~ .begin(:month ) # => 5
113+ p $~ .begin(' day' ) # => nil
114+ # @ since 3.4
115+ p $~ .begin(' century' ) # => 'begin': undefined group name reference: century (IndexError)
116+ # @else
117+ p $~ .begin(' century' ) # => `begin': undefined group name reference: century (IndexError)
118+ # @end
119+ ```
120+
121+ - ** SEE** [ m: MatchData #end]
122+
97123### def end(n) -> Integer | nil
98124
99125n 番目の部分文字列終端のオフセットを返します。
@@ -120,6 +146,32 @@ p $~.end(4) # => `end': index 4 out of matches (IndexError)
120146
121147- ** SEE** [ m: MatchData #begin]
122148
149+ ### def end(name) -> Integer | nil
150+
151+ name という名前付きグループの部分文字列終端のオフセットを返します。
152+
153+ name の名前付きグループがマッチしていなければ nil を返します。
154+
155+ - ** param** ` name ` -- 名前(シンボルか文字列)
156+
157+ - ** raise** ` IndexError ` -- 正規表現中で定義されていない name を指定した場合に発生します。
158+
159+ ``` ruby title="例"
160+ /(?<year>\d {4} ) 年(?<month>\d {1,2} ) 月(?:(?<day>\d {1,2} ) 日) ?/ =~ " 2021年1月"
161+ p $~ .end(' year' ) # => 4
162+ p $~ .end(:year ) # => 4
163+ p $~ .end(' month' ) # => 6
164+ p $~ .end(:month ) # => 6
165+ p $~ .end(' day' ) # => nil
166+ # @ since 3.4
167+ p $~ .end(' century' ) # => 'end': undefined group name reference: century (IndexError)
168+ # @else
169+ p $~ .end(' century' ) # => `end': undefined group name reference: century (IndexError)
170+ # @end
171+ ```
172+
173+ - ** SEE** [ m: MatchData #begin]
174+
123175### def captures -> [ String]
124176#@since 3.2
125177### def deconstruct -> [ String]
0 commit comments