in reply to getting stripped characters from string

Remove the ones acceptable. Then, what's left is the ones not acceptable...
  • Comment on Re: getting stripped characters from string

Replies are listed 'Best First'.
Re^2: getting stripped characters from string
by Anonymous Monk on Nov 10, 2010 at 22:48 UTC
    or, more fancily, record what you replaced (e.g. in a hash, together with the character positions):

    #!/usr/bin/perl -wl use strict; my $_field1 = 'Some Other - State & Non State'; my %invalid; $_field1 =~ s/([^A-Za-z0-9\.\, ])/push @{$invalid{$1}}, pos($_field1); + ''/ge; print "invalid char '$_' at pos @{$invalid{$_}}" for sort keys %invali +d; print "cleaned input: '$_field1'"; __END__ invalid char '&' at pos 19 invalid char '-' at pos 11 cleaned input: 'Some Other State Non State'