Skip to content
Related Articles

Related Articles

Improve Article
Ruby | StringScanner scan_until function
  • Last Updated : 12 Dec, 2019

StringScanner#scan_until() : scan_until() is a StringScanner class method which scans the string until the pattern is matched

Syntax: StringScanner.scan_until()

Parameter: StringScanner values

Return: the substring up to and including the end of the match

Example #1 :






# Ruby code for StringScanner.scan_until() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("Mon Sep 12 2018 14:39")
   
# scan_until() method
c.scan_until(/\w+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
  
# scan_until() method
c.scan_until(/\s+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"

Output :

String Scanner result of c.scan_until() form : 3

String Scanner result of c.scan_until() form : 4

Example #2 :




# Ruby code for StringScanner.scan_until() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("h ello geeks")
   
# scan_until() method
c.scan_until(/\w+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
  
  
# scan_until() method
c.scan_until(/\s+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"

Output :

String Scanner result of c.scan_until() form : 1

String Scanner result of c.scan_until() form : 2



My Personal Notes arrow_drop_up
Recommended Articles
Page :