Ruby | Regexp names() function Last Updated : 11 Jun, 2021 Comments Improve Suggest changes Like Article Like Report 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 value reg_a = /a/ # declaring Regexp value reg_b = /geeks/ # declaring Regexp value reg_c =/(?<go>.)(?<for>.)(?<it>.)/ # names method puts "Regexp names form : #{reg_a.names}\n\n" puts "Regexp names form : #{reg_b.names}\n\n" puts "Regexp names form : #{reg_c.names}\n\n" Output : Regexp names form : [] Regexp names form : [] Regexp names form : ["go", "for", "it"] Example #2 : Ruby # Ruby code for Regexp.names() method # declaring Regexp value reg_a = /geeks/ # declaring Regexp value reg_b = /(?<hi>.)(?<there>.)/ # declaring Regexp value reg_c = /(?<i>.)(?<can>.)(?<code>.)/ # names method puts "Regexp names form : #{reg_a.names}\n\n" puts "Regexp names form : #{reg_b.names}\n\n" puts "Regexp names form : #{reg_c.names}\n\n" Output : Regexp names form : [] Regexp names form : ["hi", "there"] Regexp names form : ["i", "can", "code"] Comment More infoAdvertise with us Next Article Ruby | Regexp names() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Regexp-class Similar Reads 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 ==() 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 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 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 Like