Ruby | Regexp match() function
Last Updated :
18 Dec, 2019
Regexp#match() : force_encoding?() is a Regexp class method which matches the regular expression with the string and specifies the position in the string to begin the search.
Syntax: Regexp.match()
Parameter: Regexp values
Return: regular expression with the string after matching it.
Example #1 :
reg_a = /a/
reg_b = /geeks/
reg_c = /a/
puts "Regexp match form : #{reg_a.match(" abcd ")}\n\n"
puts "Regexp match form : #{reg_b.match(" geeksforgeeks ")}\n\n"
puts "Regexp match form : #{reg_c.match(" playway ")}\n\n"
|
Output :
Regexp match form : a
Regexp match form : geeks
Regexp match form : a
Example #2 :
reg_a = /geeks/
reg_b = /problem/
reg_c = /code/
puts "Regexp match form : #{reg_a.match(" geeksforgeeks ")}\n\n"
puts "Regexp match form : #{reg_b.match(" geeksforgeeks ")}\n\n"
puts "Regexp match form : #{reg_c.match(" codeer ")}\n\n"
|
Output :
Regexp match form : geeks
Regexp match form :
Regexp match form : code
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...