Ruby | Regexp to_s() function Last Updated : 17 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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() method # declaring Regexp value reg_a = /a/ # declaring Regexp value reg_b = /\xa1\xa2/e # to_s method puts "Regexp to_s form : #{reg_a.to_s}\n\n" puts "Regexp to_s form : #{reg_b.to_s}\n\n" Output : Regexp to_s form : (?-mix:a) Regexp to_s form : (?-mix:\xa1\xa2) Example #2 : Ruby # Ruby code for Regexp.to_s() method # declaring Regexp value reg_a = /geeks/ix # declaring Regexp value reg_b = /(.)(.)/ # to_s method puts "Regexp to_s form : #{reg_a.to_s}\n\n" puts "Regexp to_s form : #{reg_b.to_s}\n\n" Output : Regexp to_s form : (?ix-m:geeks) Regexp to_s form : (?-mix:(.)(.)) Comment More infoAdvertise with us Next Article Ruby | Regexp to_s() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Regexp-class Similar Reads Ruby | Range to_s() function The to_s() is an inbuilt method in Ruby returns a string containing the given range. Syntax: range1.to_s() Parameters: The function accepts no parameter. Return Value: It returns a string containing the range. Example 1: Ruby # Ruby program for to_s() # method in Range # Initialize range range1 = (0 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 source() function Regexp#source() : source() is a Regexp class method which returns the original string of the pattern. Syntax: Regexp.source() Parameter: Regexp values Return: original string of the pattern. Example #1 : Ruby # Ruby code for Regexp.source() method # declaring Regexp value reg_a = /a/ # declaring Reg 1 min read Ruby | Matrix to_s() function The to_s() is an inbuilt method in Ruby returns a string containing the matrix as the object. Syntax: mat1.to_s() Parameters: The function needs the matrix whose string object is to be returned. Return Value: It returns a string or self. Example 1: Ruby # Ruby program for to_s() method in Matrix # I 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 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 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 | Set replace() function The replace() is an inbuilt method in Ruby which replaces the contents of the set with the contents of the given enumerable object and returns self. Syntax: s1.replace(enum) Parameters: The function accepts an enumerable object which to be replaced in the set. Return Value: It returns the self objec 1 min read Like