syker
syker

Reputation: 11272

Removing punctuation from string in Perl

How do I remove all punctuation except for spaces from a string in Perl?

Upvotes: 0

Views: 9495

Answers (2)

Ether
Ether

Reputation: 53976

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;

Upvotes: 6

ghostdog74
ghostdog74

Reputation: 342433

s/[[:punct:]]//g

Upvotes: 14

Related Questions