instance method
StringScanner#check_until
(::Regexp) -> ::String
check_until(pattern) → substring or nil
ext/strscan/strscan.c
View on GitHub ↗
static VALUE
strscan_check_until(VALUE self, VALUE re)
{
return strscan_do_scan(self, re, 0, 1, 0);
}
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:
-
Clears all match values.
-
Returns
nil.
Example
scanner.check_until(/nope/) # => nil match_values_cleared?(scanner) # => true