Ruby | Regexp source() function Last Updated : 17 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Regexp value reg_b = /\xa1\xa2/e # declaring Regexp value reg_c =/(?<go>.)(?<for>.)(?<it>.)/ # source method puts "Regexp source form : #{reg_a.source}\n\n" puts "Regexp source form : #{reg_b.source}\n\n" puts "Regexp source form : #{reg_c.source}\n\n" Output : Regexp source form : a Regexp source form : \xa1\xa2 Regexp source form : (?.)(?.)(?.) Example #2 : Ruby # Ruby code for Regexp.source() method # declaring Regexp value reg_a = /geeks/ix # declaring Regexp value reg_b = /(?<hi>.)(?<there>.)e/ # declaring Regexp value reg_c = /(?<i>.)(?<can>.)(?<code>.)/ # source method puts "Regexp source form : #{reg_a.source}\n\n" puts "Regexp source form : #{reg_b.source}\n\n" puts "Regexp source form : #{reg_c.source}\n\n" Output : Regexp source form : geeks Regexp source form : (?.)(?.)e Regexp source form : (?.)(?.)(?.) 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 | 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 =~() 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 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 Like