Skip to content
Related Articles

Related Articles

Improve Article
Ruby | StringScanner pre_match function
  • Last Updated : 10 Dec, 2019

StringScanner#pre_match() : pre_match() is a StringScanner class method which returns the pre-match (in the regular expression sense) of the last scan.

Syntax: StringScanner.pre_match()

Parameter: StringScanner values

Return: pre-match (in the regular expression sense) of the last scan

Example #1 :






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

Output :

String Scanner pre_match form : 

String Scanner pre_match form : Mon

Example #2 :




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

Output :

String Scanner pre_match form : 

String Scanner pre_match form : h

My Personal Notes arrow_drop_up
Recommended Articles
Page :