开发者

Removing punctuation from string in Perl

How do I remove all punctuation except for spaces from a st开发者_JAVA百科ring in Perl?


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


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;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜