Skip to content
instance method

StringScanner#pre_match

() -> ::String
pre_match → substring

Returns the substring that precedes the matched substring from the most recent match attempt if it was successful, or nil otherwise; see Basic Match Values:

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

scanner.pos = 3
scanner.exist?(/baz/)  # => 6
scanner.pre_match      # => "foobar" # Substring of entire string, not just target string.

scanner.exist?(/nope/) # => nil
scanner.pre_match      # => nil
See also #post_match #reset #pos= #rest also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0