Please, if you try and flame posts, get your facts straight.
1st: - is a range operator, and hence needs not be escaped when it's not
indicating a range, ie, at the beginning or end of a []
so this regex is not 'wrong'. feel free to try it.
2nd: the regex is purposely written verbose, seeing this is a newbie list and we
want to teach them, not scare them away by hard to follow code
on that note: ^\w might confuse, since, when used inside a range ( [] ),
means something totally different then outside it... hence, for comprehension i
teach \W instead
(for those wondering: outside a range, ^ means 'match beginning of
string', inside a range it means 'not')
so the short version would be:
if (/[\W.-/]){ print "illegal string" }
the verbose version would be an explicit check of every character, as described
below
hope this clears things up,
Jos Boumans
PS html tags end </tag>
Chas Owens wrote:
> On 12 Jun 2001 17:45:16 +0200, Jos Boumans wrote:
> > try this:
> >
> > unless (/^[-\.\w]+$/) { print "you cheater!" }
> >
> > this will check if from beginning to end of $_ it contains - . (not even sure
> > you need to \ the . ) or any word character (a-z A-Z and _ )
> >
> > the ^ says to start at the beginning of the string... the $ says to read till
> > end of line...
> <snip />
>
> This regexp is a little to verbose (and wrong since - is not escaped).
> Since we want a failure if any character fails to match "a-z", "A-Z",
> "0-9", "_", "-", "." we don't need to test that the whole string is
> correct, only that any character in it is wrong:
>
> if (/[^\w.\-]/) { print "you cheater!" }
>
> However, if you wanted to limit the string to $x characters you might be
> better off testing like this:
>
> unless (/^[\w.\-]{1,$x}$/) { print "you cheater!" }
>
> --
> Today is Pungenday, the 17th day of Confusion in the YOLD 3167
> Umlaut Zebra über alles!