Related Articles

Related Articles

Ruby | StringScanner match? function
  • Last Updated : 09 Dec, 2019

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: posiiton – if pattern matches otherwise return false

Example #1 :



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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"

chevron_right


Output :

String Scanner match? form : 3

String Scanner match? form : 

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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"

chevron_right


Output :

String Scanner match? form : 10

String Scanner match? form : 

My Personal Notes arrow_drop_up
Recommended Articles
Page :