Regular expression quirk?

Hello,

AFAIK, there are no possessive quantifiers in 1.9, so I expected a
syntax error from this:

re = /cats?+/
=> /cats?+/

It worked and it works, but the + is meaningless it seems:

re.match “cat”
=> #<MatchData “cat”>

re.match “cats”
=> #<MatchData “cats”>

re.match “catsssss”
=> #<MatchData “cats”>

re.match “cats+”
=> #<MatchData “cats”>

Interestingly, the + is “preserved”:

re.to_s
=> “(?-mix:cats?+)”

re.source
=> “cats?+”

Does this make sense to anyone?

Thanks,
Ammar

On Wed, Oct 27, 2010 at 12:44 PM, Ammar A. [email protected]
wrote:

AFAIK, there are no possessive quantifiers in 1.9,

You are misinformed. Where did you get that information? Please see:

http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt

Kind regards

robert

On Wed, Oct 27, 2010 at 1:47 PM, Robert K.
[email protected] wrote:

On Wed, Oct 27, 2010 at 12:44 PM, Ammar A. [email protected] wrote:

AFAIK, there are no possessive quantifiers in 1.9,

You are misinformed. Where did you get that information? Please see:

http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt

I don’t recall how I ended up with that “fact”. I was probably looking
at a very old version of that file, or confused by ({n,m}+, {n,}+,
{n}+ are possessive op. in ONIG_SYNTAX_JAVA only).

It makes perfect sense now, and quite a relief for my work.

Thanks,
Ammar

On Wed, Oct 27, 2010 at 1:58 PM, Ammar A. [email protected]
wrote:

On Wed, Oct 27, 2010 at 1:47 PM, Robert K.
[email protected] wrote:

On Wed, Oct 27, 2010 at 12:44 PM, Ammar A. [email protected] wrote:

AFAIK, there are no possessive quantifiers in 1.9,

You are misinformed. Where did you get that information? Please see:

http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt

One more thing, Read Ruby
(http://ruby.runpaint.org/regexps#quantifiers) doesn’t even mention
possessive quantifiers. Hmmm.

Not everything in Oniguruma is supported in ruby. I guess I need to
verify this further.

Thanks,
Ammar

On Wed, Oct 27, 2010 at 2:58 PM, Robert K.
[email protected] wrote:

=> nil

What else do you need to verify?

I ran similar tests and they work as expected from possessives, so I’m
sure they are supported. I would like to see it clearly stated in ruby
documentation. I logged an issue about it for Read Ruby
http://github.com/runpaint/read-ruby/issues#issue/74

Thanks again,
Ammar

On Wed, Oct 27, 2010 at 1:38 PM, Ammar A. [email protected]
wrote:

One more thing, Read Ruby
(http://ruby.runpaint.org/regexps#quantifiers) doesn’t even mention
possessive quantifiers. Hmmm.

Not everything in Oniguruma is supported in ruby. I guess I need to
verify this further.

irb(main):001:0> /a+a/ =~ “aaa”
=> 0
irb(main):002:0> /a++a/ =~ “aaa”
=> nil

What else do you need to verify?

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs