Regex question

K

Katz Bo

Code:
irb(main):113:0> /l{2}x/ =~ 'llx'
=> 0
irb(main):109:0> /(lo){2}/ =~ 'lolo'
=> 0
irb(main):110:0> /(lo){2}x/ =~ 'lolox'
=> nil
irb(main):111:0> /(?:lo){2}x/ =~ 'lolox'
=> 0

Note the third command returned nil but the fourth worked, any ideas?

Code:
$ ruby -v
ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]
 
W

W. James

Katz said:
Code:
irb(main):113:0> /l{2}x/ =~ 'llx'
=> 0
irb(main):109:0> /(lo){2}/ =~ 'lolo'
=> 0
irb(main):110:0> /(lo){2}x/ =~ 'lolox'
=> nil
irb(main):111:0> /(?:lo){2}x/ =~ 'lolox'
=> 0

Note the third command returned nil but the fourth worked, any ideas?

Code:
$ ruby -v
ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]

irb(main):001:0> /(lo){2}x/ =~ 'lolox'
=> 0
irb(main):002:0> RUBY_VERSION
=> "1.8.7"

--
 
P

Paul Smith

Katz said:
Code:
irb(main):113:0> /l{2}x/ =~ 'llx'
=> 0
irb(main):109:0> /(lo){2}/ =~ 'lolo'
=> 0
irb(main):110:0> /(lo){2}x/ =~ 'lolox'
=> nil
irb(main):111:0> /(?:lo){2}x/ =~ 'lolox'
=> 0

Note the third command returned nil but the fourth worked, any ideas?

Seems like a bug.

irb(main):110:0> /(lo){2,3}x/ =~ 'lolox'
irb(main):110:0> /(lo){1,2}x/ =~ 'lolox'
irb(main):110:0> /(lo){2,}x/ =~ 'lolox'
irb(main):110:0> /(lo){,2}x/ =~ 'lolox'

all work for me on ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]

It's just {2} that doesn't work.
 
K

Katz Bo

Katz said:
Same for me. I actually had tried what you tried too. Also, {2,2} won't
work either.

Sorry for double posting, post too quick.
Yet another thing is, {1} works:

/(lo){1}x/ =~ 'lololox' # => 4
/(lo){2}x/ =~ 'lololox' # => nil
/(lo){3}x/ =~ 'lololox' # => nil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top