in reply to Re: Inverse regexes for input validation
in thread Inverse regexes for input validation

thanks for that, seems I overcomplicated it far too much and wasn't using local vars properly

turns out all I needed was
my ($text) = @_; $text =~ s/[^A-Za-z0-9 -]+//g; return $text;
thanks very much for the help.

Replies are listed 'Best First'.
Re^3: Inverse regexes for input validation
by graff (Chancellor) on Mar 29, 2007 at 01:15 UTC
    Not that it makes a whole lot of difference in your case, but the "tr///" operator is especially good for this sort of thing -- it's demonstrably faster than "s///" (utf8 wide characters don't even seem to slow it down), and the syntax is a little easier:
    my ( $text ) = shift; $text =~ tr/ 0-9A-Za-z-//cd; return $text;
    The "c" modifier says the match should apply to the complement of the characters cited, and with no characters in the replacement side, "d" says delete all matched characters.