Skip to content
instance method

StringScanner#captures

() -> ::Array[::String]?
captures → substring_array or nil

Returns the array of captured match values at indexes (1..) if the most recent match attempt succeeded, or nil otherwise:

Example
scanner = StringScanner.new('Fri Dec 12 1975 14:39')
scanner.captures         # => nil

scanner.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+) /)
scanner.captures         # => ["Fri", "Dec", "12"]
scanner.values_at(*0..4) # => ["Fri Dec 12 ", "Fri", "Dec", "12", nil]

scanner.exist?(/Fri/)
scanner.captures         # => []

scanner.scan(/nope/)
scanner.captures         # => nil
See also #beginning_of_line? #charpos #[] #check also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0