Regexp#options in 1.7.2

Regexp objects in Ruby 1.7.2 have an ‘options’ method. Poking around, I se
that it returns an integer version of the options flags, but can’t figure
out what the bit in position 8 (assuming far right is position 1) is
supposed to be:

re = Regexp.new(“ruby”, Regexp::IGNORECASE | Regexp::EXTENDED)
p re.options # 131 (000000000000000000000000010000011)
re = Regexp.new(“ruby”, Regexp::IGNORECASE )
p re.options # 129 (000000000000000000000000010000001)

I couldn’t find any regexp constants defined for 128. What is this value
for?

Thanks,

James

Hi,

···

In message “regexp#options in 1.7.2” on 02/06/03, james@rubyxml.com james@rubyxml.com writes:

Regexp objects in Ruby 1.7.2 have an ‘options’ method. Poking around, I se
that it returns an integer version of the options flags, but can’t figure
out what the bit in position 8 (assuming far right is position 1) is
supposed to be:

re = Regexp.new(“ruby”, Regexp::IGNORECASE | Regexp::EXTENDED)
p re.options # 131 (000000000000000000000000010000011)
re = Regexp.new(“ruby”, Regexp::IGNORECASE )
p re.options # 129 (000000000000000000000000010000001)

I couldn’t find any regexp constants defined for 128. What is this value
for?

It’s revealing internal optimize flags (128 means “pattern begins with
exact string”). Should I hide them?

						matz.

From: Yukihiro Matsumoto [mailto:matz@ruby-lang.org]
Sent: Monday, June 03, 2002 8:10 AM
To: ruby-talk ML
Subject: Re: regexp#options in 1.7.2
Importance: High

Hi,

I couldn’t find any regexp constants defined for 128. What is
this value
for?

It’s revealing internal optimize flags (128 means “pattern begins with
exact string”). Should I hide them?

No, this is potentially useful information.

I wonder if Regexp#options should take an optional bit mask parameter.
Then you could query for, or omit, particular bit sets:

MASK_BEGINS_WITH_EXACT = ~128
p re.options( MASK_BEGINS_WITH_EXACT ) # omit bit at location 8

Thanks,

James

···

-----Original Message-----
In message “regexp#options in 1.7.2” > on 02/06/03, james@rubyxml.com james@rubyxml.com writes:

  					matz.

Hi,

···

In message “RE: regexp#options in 1.7.2” on 02/06/04, james@rubyxml.com james@rubyxml.com writes:

I wonder if Regexp#options should take an optional bit mask parameter.
Then you could query for, or omit, particular bit sets:

These optimize bits highly depend on the implementation of regex
engine. For example, we already have alternative regex engine
code-named “Oniguruma”, which does not provide this bit.

						matz.

I wonder if Regexp#options should take an optional bit mask parameter.
Then you could query for, or omit, particular bit sets:

These optimize bits highly depend on the implementation of regex
engine. For example, we already have alternative regex engine
code-named “Oniguruma”, which does not provide this bit.

Still, options returns an integer; to get the low-order bits for the more
stable values one needs to use some bit math:

p ( re.options & Regexp::EXTENDED ).zero? # See if EXTENDED is set

which is (perhaps marginally) easier/clearer like this:

p ( re.options( Regexp::EXTENDED ).zero? # See if EXTENDED is set

James

···
  					matz.