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 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 code for Regexp.new() method # declaring Regexp value reg_a = Regexp . new ( '/Beginner/' ) # declaring Regexp value reg_b = Regexp . new ( '/(?<Beginner>.)(?<for>.)(?<Beginner>.)/' ) # 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:\/Beginner\/) Regexp new form : (?-mix:\/(?.)(? .)(? .)\/) Regexp new form : (?-mix:\*?????{}.)
Contact Us