Ruby | Regexp new() function Last Updated : 17 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 Regexp value reg_c = Regexp.new('\*?{}.') # new method puts "Regexp new form : #{reg_a}\n\n" puts "Regexp new form : #{reg_c}\n\n" Output : Regexp new form : (?-mix:\/a\/) Regexp new form : (?-mix:\*?{}.) Example #2 : Ruby # Ruby code for Regexp.new() method # declaring Regexp value reg_a = Regexp.new('/geeks/') # declaring Regexp value reg_b = Regexp.new('/(?<geeks>.)(?<for>.)(?<geeks>.)/') # declaring Regexp value reg_c = Regexp.new('\*?????{}.') # new method puts "Regexp new form : #{reg_a}\n\n" puts "Regexp new form : #{reg_b}\n\n" puts "Regexp new form : #{reg_c}\n\n" Output : Regexp new form : (?-mix:\/geeks\/) Regexp new form : (?-mix:\/(?.)(?.)(?.)\/) Regexp new form : (?-mix:\*?????{}.) Comment More infoAdvertise with us Next Article Ruby | Regexp new() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Regexp-class Similar Reads 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 ==() 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 | Range new() function The new() is an inbuilt method in Ruby returns a new range of numbers. Syntax: range1.new(first, last) Parameters: The function accepts first and last which is the range that is to be created. Return Value: It returns the range of numbers. Example 1: Ruby # Ruby program for new() # method in Range # 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 inspect() function Regexp#inspect() is a Regexp class method which produces a formatted string-version of regular expression. Syntax: Regexp.inspect()Parameter: Regexp valuesReturn: a formatted string-version of regular expression Example #1 :  Ruby # Ruby code for Regexp.inspect() method # declaring Regexp value 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 options() function Regexp#options() : options() is a Regexp class method which returns the set of bits corresponding to the options used when creating the Regular Expression. Syntax: Regexp.options() Parameter: Regexp values Return: set of bits corresponding to the options used when creating the Regular Expression. Ex 1 min read Ruby | Queue new() function The new() is an inbuilt function in Ruby creates a new queue of the given name. Syntax: q_name = Queue.new() Parameters: The function does not takes any parameter. Return Value: It creates a new queue. Example 1: CPP #Ruby program for new () function in Queue #Create a new QUEUE q1 q1 = Queue.new #p 1 min read Like