Skip to content
instance method

StringScanner#matched_size

() -> ::Integer?
matched_size → substring_size or nil

Returns the size (in bytes) of the matched substring from the most recent match match attempt if it was successful, or nil otherwise; see Basic Matched Values:

Example
scanner = StringScanner.new('foobarbaz')
scanner.matched_size   # => nil

pos = 3
scanner.exist?(/baz/)  # => 9
scanner.matched_size   # => 3

scanner.exist?(/nope/) # => nil
scanner.matched_size   # => nil
See also #matched? #named_captures #matched #peek also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0