Skip to content
Related Articles

Related Articles

Ruby | Regexp options() function
  • Last Updated : 17 Dec, 2019

Regexp#options() : options() is a Regexp class method which returns the set of bits corresponding to the options used when creating the Regular Expression.

Syntax: Regexp.options()

Parameter: Regexp values

Return: set of bits corresponding to the options used when creating the Regular Expression.

Example #1 :



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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 =/(?<go>.)(?<for>.)(?<it>.)/
  
  
#  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"

chevron_right


Output :

Regexp options form : 0

Regexp options form : 16

Regexp options form : 0

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for Regexp.options() method
  
# declaring Regexp value
reg_a = /geeks/ix
  
# declaring Regexp value
reg_b = /(?<hi>.)(?<there>.)e/
  
# declaring Regexp value
reg_c = /(?<i>.)(?<can>.)(?<code>.)/
  
  
#  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"

chevron_right


Output :

Regexp options form : 3

Regexp options form : 0

Regexp options form : 0

My Personal Notes arrow_drop_up
Recommended Articles
Page :