Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Regexp#names

names → array_of_names

Returns an array of names of captures (see Named Captures):

Example
/(?<foo>.)(?<bar>.)(?<baz>.)/.names # => ["foo", "bar", "baz"]
/(?<foo>.)(?<foo>.)/.names          # => ["foo"]
/(.)(.)/.names                      # => []
See also #named_captures #options #match? #source also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0