Dr.Ruud wrote:
> Jim Schueckler schreef:
> 
>>I need to remove all characters from a string except 'a'..'z',
>>'A'..'Z', and '0'..'9'.
>>
>>Could somebody please tell me the magicWords for:
>>   $newstring = magicWords($oldstring);    ???
>>
>>I am absolutely new to Perl and regular expressions, so please don't
>>assume I know anything that everybody else knows. :-)
> 
> What makes you think that a regular expression is needed or even the
> best solution?
> 
> See `perldoc -f tr`, which will tell you to read on in `perldoc perlop`.
> Search for tr/ at the perldoc-prompt to jump to the documentation of
> tr///.
> 
> You might actually be looking for this:
> 
>   (my $newstring = $oldstring) =~ tr/0-9A-Za-z/ /cds;
> 
> which replaces runs of non-alphanumeric characters with a single space.

No it doesn't:

$ perl -le' ( $_ = q[&[EMAIL PROTECTED] ) =~ tr/0-9A-Za-z/ /cds; print'
ghjk76565hgfg

You would have to use the substitution operator to replace runs of
non-alphanumeric characters with a single space.

$ perl -le' ( $_ = q[&[EMAIL PROTECTED] ) =~ s/[^0-9A-Za-z]+/ /g; print'
 ghjk 76565 hgfg




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to