[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] 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.
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. :)
j