in reply to Re: Regex for weird characters
in thread Regex for weird characters

The idea is okay, but why match the whole string if it's sufficiant to fail as soon as one character fails? So instead of
$text !~ /^[a-z0-9,]*$/i
this should give the same result:
$text =~ /[^a-z0-9,]/i

$\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

Replies are listed 'Best First'.
Re^3: Regex for weird characters
by kutsu (Priest) on Sep 27, 2004 at 15:37 UTC

    you could shorten Skeeve's regex further using character classes, acutally it's the same length cause I added spaces ;)

    $text =~ /[^\w\d\s,]/;

    Update: switched /w for \w (++ to graff for pointing out my typo)

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

      You absolutely can not use perl's shortcut character classes. \w matches different things depending on your locale. If you have a German locale, for instance, it will match ß.