Ruby Regexp ==()
函数
Regexp#==() : ==()
是一个Regexp类的方法,用于比较两个正则表达式。
语法。Regexp.==()
参数。Regexp值
返回:true – 如果两个正则表达式相等,否则返回false。
例子 #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"
输出:
Regexp == form : false
Regexp == form : false
Regexp == form : true
例子 #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"
输出:
Regexp == form : false
Regexp == form : true
Regexp == form : false