Ruby | Regexp escape() function Last Updated : 17 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 regular expression. Example #1 : Ruby # Ruby code for Regexp.escape() method # declaring Regexp value reg_a = Regexp.escape('/a/') # declaring Regexp value reg_c = Regexp.escape('\*?{}.') # escape method puts "Regexp escape form : #{reg_a}\n\n" puts "Regexp escape form : #{reg_c}\n\n" Output : Regexp escape form : /a/ Regexp escape form : \\\*\?\{\}\. Example #2 : Ruby # Ruby code for Regexp.escape() method # declaring Regexp value reg_a = Regexp.escape('/geeks/') # declaring Regexp value reg_b = Regexp.escape('/(?<geeks>.)(?<for>.)(?<geeks>.)/') # declaring Regexp value reg_c = Regexp.escape('\*?????{}.') # escape method puts "Regexp escape form : #{reg_a}\n\n" puts "Regexp escape form : #{reg_b}\n\n" puts "Regexp escape form : #{reg_c}\n\n" Output : Regexp escape form : /geeks/ Regexp escape form : /\(\?\.\)\(\?\.\)\(\?\.\)/ Regexp escape form : \\\*\?\?\?\?\?\{\}\. Comment More infoAdvertise with us Next Article Ruby | Regexp escape() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Regexp-class Similar Reads Ruby | Regexp compile() function Regexp#compile() : compile() is a Regexp class method which completes a new Regular Expression. Syntax: Regexp.compile() Parameter: Regexp values Return: creates a new Regular Expression. Example #1 : Ruby # Ruby code for Regexp.compile() method # declaring Regexp value reg_a = Regexp.compile(/a/) # 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 casefold?() function Regexp#casefold?() : casefold?() is a Regexp class method which returns the value of the case-insensitive flag of regular expressions. Syntax: Regexp.casefold?() Parameter: Regexp values Return: value of the case-insensitive flag of regular expressions Example #1 : Ruby # Ruby code for Regexp.casefo 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 ==() 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 encoding() function Regexp#encoding() : encoding() is a Regexp class method which returns the encoding value of the regular expressions. Syntax: Regexp.encoding() Parameter: Regexp values Return: encoding value of the regular expressions Example #1 : Ruby # Ruby code for Regexp.encoding() method # declaring Regexp valu 1 min read Ruby | Regexp named_captures() function Regexp#named_captures() : named_captures() is a Regexp class method which returns a hash representing information about named captures of regular expression. A key of the hash is a name of the named capture produces a formatted string-version of the regular expression. Syntax: Regexp.named_captures( 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 Like