Re: Regexp non-alphanumerics to spaces



"John W. Krahn" schreef:
Rob Dixon:
Grant:

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?

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

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

Isn't \s already part of [[:^alnum:]]?

Alternative:

s/[_\W]+/ /g;

--
Affijn, Ruud

"Gewoon is een tijger."
.



Relevant Pages