Skip to content
instance method

StringScanner#check_until

(::Regexp) -> ::String
check_until(pattern) → substring or nil

Attempts to match the given pattern anywhere (at any position) in the target substring; does not modify the positions.

If the match succeeds:

  • Sets all match values.

  • Returns the matched substring, which extends from the current position to the end of the matched substring.

Example
scanner = StringScanner.new('foobarbazbatbam')
scanner.pos = 6
scanner.check_until(/bat/) # => "bazbat"
put_match_values(scanner)
# Basic match values:
#   matched?:       true
#   matched_size:   3
#   pre_match:      "foobarbaz"
#   matched  :      "bat"
#   post_match:     "bam"
# Captured match values:
#   size:           1
#   captures:       []
#   named_captures: {}
#   values_at:      ["bat", nil]
#   []:
#     [0]:          "bat"
#     [1]:          nil
put_situation(scanner)
# Situation:
#   pos:       6
#   charpos:   6
#   rest:      "bazbatbam"
#   rest_size: 9

If the match fails:

Example
scanner.check_until(/nope/)    # => nil
match_values_cleared?(scanner) # => true
See also #check #concat #charpos #eos? also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0