On 9/15/06, Paul Lutus <nospam / nosite.zzz> wrote:
> Bart Braem wrote:
>
> > I'm trying to validate a user mail address for a fixed domain with the
> > rule string =~ /\w+\.\w+/
> > this matches firstname.lastname, which is what I want.
> > But it also matches fistname.lastname / somedomain.com, which is not what I
> > want.

> Have you tried:
>
> string =~ /^\w+\.\w+$/
>
> "^" means match at the beginning of the string, "$" means match at the end.
> IOW the example must match the entire string. Is this what you wanted?

Actually "$" matches at the end of the string or the first line break
('\n') whichever comes first.

\z literally matches at the end of the string, whereas
\Z matches either the end of the string unless the string ends with
'\n' in which case it matches just before that final '\n'

And if you want to match just before the first of an optional series
of trailing '\n's  I think that this:

    \n*\Z

works as the end of the RE.
-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/