case where regex range should raise

  • Thread starter Simon Strandgaard
  • Start date
S

Simon Strandgaard

irb(main):001:0> re = /bx{,2}c/
=> /bx{,2}c/
irb(main):002:0> re.match("abxcd")
=> nil
irb(main):003:0> re = /bx{0,2}c/
=> /bx{0,2}c/
irb(main):004:0> re.match("abxcd")
=> #<MatchData:0x81c46d0>
irb(main):005:0>


Is {,2} notation supported ?
If not.. shouldn't it raise an exception ?
 
R

Robert Klemme

Simon Strandgaard said:
irb(main):001:0> re = /bx{,2}c/
=> /bx{,2}c/
irb(main):002:0> re.match("abxcd")
=> nil
irb(main):003:0> re = /bx{0,2}c/
=> /bx{0,2}c/
irb(main):004:0> re.match("abxcd")
=> #<MatchData:0x81c46d0>
irb(main):005:0>


Is {,2} notation supported ?
If not.. shouldn't it raise an exception ?

Interestingly enough negative values do not cause errors but do not match
either:

irb(main):008:0> /f{-1,2}/ =~ "aaffff"
=> nil

IMHO this should either raise an error or match, since there are more
than -1 "f"'s in the string.

Regards

robert
 
T

ts

S> irb(main):001:0> re = /bx{,2}c/
S> => /bx{,2}c/
S> irb(main):002:0> re.match("abxcd")
S> => nil

svg% ruby -e 'p /bx{,2}x/ =~ "abx{,2}xy"'
1
svg%


Guy Decoux
 
R

Robert Klemme

ts said:
S> irb(main):001:0> re = /bx{,2}c/
S> => /bx{,2}c/
S> irb(main):002:0> re.match("abxcd")
S> => nil

svg% ruby -e 'p /bx{,2}x/ =~ "abx{,2}xy"'
1
svg%

Hm. Wouldn't you say that in this case {} should be escaped? I mean, the
missing number (or the negative number) is more likely an (typing) error
than on purpose.

robert
 

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
474,137
Messages
2,570,795
Members
47,342
Latest member
eixataze

Latest Threads

Top