How do I remove all punctuation except for spaces from a string in Perl?
+5
A:
Spaces aren't punctuation, and you aren't specific about whether you want to keep just spaces or all kinds of whitespace, but this substitution will remove all types of punctuation (since there are more forms of punctuation than just ! , and .).
$string =~ s/[[:punct:]]//g;
Ether
2010-09-01 02:49:02
And there are more letters than a-zA-Z.
strager
2010-09-01 03:04:50
There are a lot more "letters" than just A to Z. That has nothing to do with the right answer though.
brian d foy
2010-09-01 07:41:16
No need for the "i" modifier. I've never heard of upper/lower cased punctuation.
runrig
2010-09-01 16:17:15
@runrig: yep, that was a holdover from my first answer which had `[^a-z]`.
Ether
2010-09-01 16:29:47