[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

case where regex range should raise

Melanie Fielder

10/9/2003 10:06:00 AM

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 ?


--
Simon Strandgaard


3 Answers

Robert Klemme

10/9/2003 10:13:00 AM

0


"Simon Strandgaard" <none> schrieb im Newsbeitrag
news:3f853379$0$69912$edfadb0f@dread12.news.tele.dk...
> 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

ts

10/9/2003 10:18:00 AM

0

>>>>> "S" == Simon Strandgaard <none@pragprog.com> writes:

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



Robert Klemme

10/9/2003 11:23:00 AM

0


"ts" <decoux@moulon.inra.fr> schrieb im Newsbeitrag
news:200310091017.h99AHlH10874@moulon.inra.fr...
> >>>>> "S" == Simon Strandgaard <none@pragprog.com> writes:
>
> 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