Rob Dixon wrote:
> Grant wrote:
>>
>> Hello, can you guys show me how to convert each non-alphanumeric
>> character in a string to a space, and then convert any number of
>> consecutive spaces in the string to a single space?
>>
>> If I need to specify exactly which characters I want converted to
>> spaces, I'd be happy with just the "." character.
> 
> Hi Grant.
> 
> $text =~ s/[^[:alnum:]]/ /g;
> $text =~ s/\s+/ /g;
> 
> will do what you want.

Or with one regexp:

$text =~ s/[[:^alnum:]\s]+/ /g;




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

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


Reply via email to