Ruby | Regexp =~() function Last Updated : 04 Sep, 2021 Comments Improve Suggest changes Like Article Like Report 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 reg_a = /a/ # declaring Regexp value reg_b = /geeks/ # declaring Regexp value reg_c = /a/ # =~ method puts "Regexp =~ form : #{reg_a =~ "happy"}\n\n" puts "Regexp =~ form : #{reg_b =~ "geeksforgeeks"}\n\n" puts "Regexp =~ form : #{reg_c =~ "goal"}\n\n" Output : Regexp =~ form : 1 Regexp =~ form : 0 Regexp =~ form : 2 Example #2 : Ruby # Ruby code for Regexp.=~() method # declaring Regexp value reg_a = /geeks/ # declaring Regexp value reg_b = /problem/ # declaring Regexp value reg_c = /code/ # =~ method puts "Regexp =~ form : #{reg_a =~ "geeksforgeeks"}\n\n" puts "Regexp =~ form : #{reg_b =~ "property"}\n\n" puts "Regexp =~ form : #{reg_c =~ "codemonk"}\n\n" Output : Regexp =~ form : 0 Regexp =~ form : Regexp =~ form : 0 Comment More infoAdvertise with us Next Article Ruby | Regexp =~() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Regexp-class Similar Reads 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 eql?() function Regexp#eql?() : eql?() is a Regexp class method which matches the character in two regular expression. Syntax: Regexp.eql?() Parameter: Regexp values Return: true - if two regular expressions matches string otherwise return false Example #1 : Ruby # Ruby code for Regexp.eql?() method # declaring Reg 1 min read Ruby | Regexp new() function Regexp#new() : new() is a Regexp class method which returns a new regular expression pattern. Syntax: Regexp.new() Parameter: Regexp values Return: a new regular expression pattern Example #1 : Ruby # Ruby code for Regexp.new() method # declaring Regexp value reg_a = Regexp.new('/a/') # declaring Re 1 min read 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 to_s() function Regexp#to_s() : to_s() is a Regexp class method which returns the string containing the regular expression with the same semantics. Syntax: Regexp.to_s() Parameter: Regexp values Return: string containing the regular expression with the same semantics. Example #1 : Ruby # Ruby code for Regexp.to_s() 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 Ruby | Regexp match() function 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 : Ru 1 min read Ruby | Regexp names() function Regexp#names() : names() is a Regexp class method which produces a formatted string-version of regular expression. Syntax: Regexp.names()Parameter: Regexp valuesReturn: a formatted string-version of regular expression Example #1 :  Ruby # Ruby code for Regexp.names() method # declaring Regexp valu 1 min read Ruby | Regexp escape() function Regexp#escape() : escape() is a Regexp class method which returns a new string by escaping any characters that would have special meaning in a regular expression. Syntax: Regexp.escape() Parameter: Regexp values Return: a new string by escaping any characters that would have special meaning in a reg 1 min read Like