Open In App

Ruby | Regexp ==() function

Last Updated : 17 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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 code for Regexp.==() method
  
# declaring Regexp value
reg_a = /a/
  
# declaring Regexp value
reg_b = /geeks/
  
# declaring Regexp value
reg_c = /a/
  
  
#  == method
puts "Regexp == form : #{reg_a == reg_b}\n\n"
  
puts "Regexp == form : #{reg_b == reg_c}\n\n"
  
puts "Regexp == form : #{reg_c == reg_a}\n\n"


Output :

Regexp == form : false

Regexp == form : false

Regexp == form : true

Example #2 :




# Ruby code for Regexp.==() method
  
# declaring Regexp value
reg_a = /geeks/
  
# declaring Regexp value
reg_b = /problem/
  
# declaring Regexp value
reg_c = /code/
  
  
#  == method
puts "Regexp == form : #{reg_a == reg_b}\n\n"
  
puts "Regexp == form : #{reg_b == reg_b}\n\n"
  
puts "Regexp == form : #{reg_c == reg_a}\n\n"


Output :

Regexp == form : false

Regexp == form : true

Regexp == form : false


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads