Ruby | Symbol match function
Last Updated :
09 Dec, 2019
Symbol#match() : match() is a Symbol class method which matches the pattern with symbol.
Syntax: Symbol.match()
Parameter: Symbol values
Return: position – if pattern matches the Symbol otherwise return nil
Example #1 :
a = :aBcDeF
b = : "\u{e4 f6 fc}"
c = : ABCDEF
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
puts "Symbol a match form : #{a.match(/D/)}\n\n"
puts "Symbol b match form : #{b.match(/o/)}\n\n"
puts "Symbol c match form : #{c.match(/C/)}\n\n"
|
Output :
Symbol a : aBcDeF
Symbol b : äöü
Symbol c : ABCDEF
Symbol a match form : 3
Symbol b match form :
Symbol c match form : 2
Example #2 :
a = :geeks
b = : "\u{e5 f6 f3}"
c = : GEEKS
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
puts "Symbol a match form : #{a.match(/g/)}\n\n"
puts "Symbol b match form : #{b.match(/a/)}\n\n"
puts "Symbol c match form : #{c.match(/EE/)}\n\n"
|
Output :
Symbol a : geeks
Symbol b : åöó
Symbol c : GEEKS
Symbol a match form : 0
Symbol b match form :
Symbol c match form : 1
Share your thoughts in the comments
Please Login to comment...