红宝石 |正则表达式选项()函数
Regexp#options() : options()是一个 Regexp 类方法,它返回与创建正则表达式时使用的选项相对应的位集。
Syntax: Regexp.options()
Parameter: Regexp values
Return: set of bits corresponding to the options used when creating the Regular Expression.
示例 #1:
# Ruby code for Regexp.options() method
# declaring Regexp value
reg_a = /a/
# declaring Regexp value
reg_b = /\xa1\xa2/e
# declaring Regexp value
reg_c =/(?.)(?.)(?.)/
# options method
puts "Regexp options form : #{reg_a.options}\n\n"
puts "Regexp options form : #{reg_b.options}\n\n"
puts "Regexp options form : #{reg_c.options}\n\n"
输出 :
Regexp options form : 0
Regexp options form : 16
Regexp options form : 0
示例 #2:
# Ruby code for Regexp.options() method
# declaring Regexp value
reg_a = /geeks/ix
# declaring Regexp value
reg_b = /(?.)(?.)e/
# declaring Regexp value
reg_c = /(?.)(?.)(?.)/
# options method
puts "Regexp options form : #{reg_a.options}\n\n"
puts "Regexp options form : #{reg_b.options}\n\n"
puts "Regexp options form : #{reg_c.options}\n\n"
输出 :
Regexp options form : 3
Regexp options form : 0
Regexp options form : 0