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 :
# Ruby code for Regexp.match() method # declaring Regexp value reg_a = /a/ # declaring Regexp value reg_b = /geeks/ # declaring Regexp value reg_c = /a/ # match method 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" |
chevron_right
filter_none
Output :
Regexp match form : a Regexp match form : geeks Regexp match form : a
Example #2 :
# Ruby code for Regexp.match() method # declaring Regexp value reg_a = /geeks/ # declaring Regexp value reg_b = /problem/ # declaring Regexp value reg_c = /code/ # match method 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" |
chevron_right
filter_none
Output :
Regexp match form : geeks Regexp match form : Regexp match form : code
Recommended Posts:
- Ruby | Regexp =~() function
- Ruby | Regexp ===() function
- Ruby | Regexp new() function
- Ruby | Regexp ==() function
- Ruby | Regexp eql?() function
- Ruby | StringScanner match? function
- Ruby | Symbol match function
- Ruby | Regexp options() function
- Ruby | Regexp casefold?() function
- Ruby | Regexp names() function
- Ruby | Regexp hash() function
- Ruby | Regexp fixed_encoding?() function
- Ruby | Regexp encoding() function
- Ruby | Regexp inspect() function
- Ruby | Regexp quote() function
- Ruby | Regexp compile() function
- Ruby | Regexp to_s() function
- Ruby | Regexp source() function
- Ruby | Regexp named_captures() function
- Ruby | Regexp escape() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

