Skip to content
Related Articles

Related Articles

Improve Article
Ruby | StringScanner matched? function
  • Last Updated : 09 Dec, 2019

StringScanner#matched?() : matched?() is a StringScanner class method which checks whether the last match was successful.

Syntax: StringScanner.matched?()

Parameter: StringScanner values

Return: true – if the last match was successful otherwise return false

Example #1 :






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

Output :

String Scanner matched? form : false

String Scanner matched? form : true

Example #2 :




# Ruby code for StringScanner.matched?() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("hellogeeks")
  
c.match?(/\s+/)
# matched?() method
puts "String Scanner matched? form : #{c.matched?()}\n\n"
  
c.match?(/\w+/)
# matched?() method
puts "String Scanner matched? form : #{c.matched?()}\n\n"

Output :

String Scanner matched? form : false

String Scanner matched? form : true
My Personal Notes arrow_drop_up
Recommended Articles
Page :