Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | StringScanner match? function

  • Last Updated : 10 Sep, 2021

StringScanner#match?() : match?() is a StringScanner class method which checks whether the given pattern is matched from the current scan pointer.

Syntax: StringScanner.match?()

Parameter: StringScanner values

Return: position – if pattern matches otherwise return false

Example #1 :




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

Output :

String Scanner match? form : 3

String Scanner match? form : 

Example #2 :




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

Output :

String Scanner match? form : 10

String Scanner match? form : 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!