红宝石 |正则表达式 eql?()函数
Regexp#eql?() : eql?()是一个 Regexp 类方法,它匹配两个正则表达式中的字符。
Syntax: Regexp.eql?()
Parameter: Regexp values
Return: true – if two regular expressions matches string otherwise return false
示例 #1:
# Ruby code for Regexp.eql?() method
# declaring Regexp value
reg_a = /a/
# declaring Regexp value
reg_b = /geeks/
# declaring Regexp value
reg_c = /a/
# eql? method
puts "Regexp eql? form : #{reg_a.eql? "happy"}\n\n"
puts "Regexp eql? form : #{reg_b.eql?reg_b}\n\n"
puts "Regexp eql? form : #{reg_c.eql? "goal"}\n\n"
输出 :
Regexp eql? form : false
Regexp eql? form : true
Regexp eql? form : false
示例 #2:
# Ruby code for Regexp.eql?() method
# declaring Regexp value
reg_a = /geeks/
# declaring Regexp value
reg_b = /problem/
# declaring Regexp value
reg_c = /code/
# eql? method
puts "Regexp eql? form : #{reg_a.eql? "happy"}\n\n"
puts "Regexp eql? form : #{reg_b.eql?reg_b}\n\n"
puts "Regexp eql? form : #{reg_c.eql? "goal"}\n\n"
输出 :
Regexp eql? form : false
Regexp eql? form : true
Regexp eql? form : false