红宝石 |正则表达式 ==()函数
Regexp#==() : ==()是一个比较两个正则表达式的 Regexp 类方法。
Syntax: Regexp.==()
Parameter: Regexp values
Return: true – if two regular expressions are equal otherwise return 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