How about this?

   #Substitute any character that is not one of the ones in
   #our character class with nothing

   $newstring =~ s/[^a-zA-Z0-9]//g;


Note the '^' at the start of the character class.  In a character class
it means "not", as in "not these characters".  If you see it at the
start of a regular expression, it denotes the start of the string.  The
'g' at the end means to keep substituting for all matches in the string.

Check out 'perldoc perlop' and look for the section called "Quotes and
Quote-like Operators" for more information on s///.





-----Original Message-----
From: Jim Schueckler [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 25, 2006 2:27 PM
To: beginners@perl.org
Subject: Using a regular expression to remove all except
certaincharacters.

Hi,
I need to remove all characters from a string except 'a'..'z', 'A'..'Z',
and '0'..'9'.

<snip>


--
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