[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] FW: Huh?
-----Original Message-----
From: Thompson, Kenn [mailto:KThompson@heiskell.com]
Sent: Wednesday, January 17, 2007 10:49 AM
To: Jay Hannah
Subject: RE: Huh?
-->>
-->> > Just ran across this and it stuck me as weird. Any idea why this
-->> happens?
-->> >
-->> > Given a regex "^$|^\d{1,7}$" , the rule says
-->> > "A 0 length string OR a number 1 to 7 characters in length".
-->>
-->> It does? Are you sure about that first dollar sign? Wacky.
Well, it kind of did. The test script passed it, but the app did not.
-->>
-->> In Perl the regex you describe would be
-->>
-->> /^(|\d{1,7})$/ (untested)
-->>
-->> or
-->>
-->> /^\d{1,7}?$/ (untested)
-->>
-->> ^ and $ would only occur at the very start and the very end.
-->>
-->> > Given a regex "^\d{1,7}|^$" , the rule says
-->> > "A number 1 to 7 characters in length OR a 0 length string ".
-->> >
-->> > For reasons I can't seem to fathom, the first regex evals the
-->> > way I want, the second fails the empty string test. Ever seen
-->> > this before? Perhaps it's just a weird .NET regex quirk?
-->>
-->> Uhh... I think my examples would pass in Perl. I can't
-->> comment on .NET off the top of my head. :)
-->>
It's weird that it didn't complain about the multiple $. Your examples
work
as written tho (and make more sense to me). I forgot about the parens
usage.
I guess I need to go back to regex school. ;)