Ruby | Regexp match() function Last Updated : 18 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 # 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" Output : Regexp match form : a Regexp match form : geeks Regexp match form : a Example #2 : Ruby # 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" Output : Regexp match form : geeks Regexp match form : Regexp match form : code Comment More infoAdvertise with us Next Article Ruby | Regexp match() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Regexp-class Similar Reads Ruby | Regexp hash() function Regexp#force_encoding?() : force_encoding?() is a Regexp class method which returns the hash based on the text and options of this regular expression. Syntax: Regexp.hash() Parameter: Regexp values Return: the hash based on the text and options of this regular expression. Example #1 : Ruby # Ruby co 1 min read Ruby | Regexp ==() function Regexp#==() : ==() is a Regexp class method which compares two regular expressions. Syntax: Regexp.==() Parameter: Regexp values Return: true - if two regular expressions are equal otherwise return false Example #1 : Ruby # Ruby code for Regexp.==() method # declaring Regexp value reg_a = /a/ # decl 1 min read Ruby | Regexp ===() function Regexp#===() : ===() is a Regexp class method which compares the equality of two regular expressions. Syntax: Regexp.===() Parameter: Regexp values Return: true - if two regular expressions has equality otherwise return false Example #1 : Ruby # Ruby code for Regexp.===() method # declaring Regexp v 1 min read Ruby | Regexp =~() function Regexp#=~() : =~() is a Regexp class method which matches a regular expression against a string. Syntax: Regexp.=~()Parameter: Regexp valuesReturn: true - if two regular expressions matches string otherwise return false Example #1 :  Ruby # Ruby code for Regexp.=~() method # declaring Regexp value 1 min read Ruby | Regexp quote() function Regexp#quote() : quote() is a Regexp class method which escapes any characters that would have special meaning in a regular expression. Syntax: Regexp.quote() Parameter: Regexp values Return: escapes any characters that would have special meaning in a regular expression. Example #1 : Ruby # Ruby cod 1 min read Like