开发者

Removing punctuation from string in Perl

开发者 https://www.devze.com 2023-01-14 14:08 出处:网络
How do I remove all punctuation except for spaces from a st开发者_JAVA百科ring in Perl?s/[[:punct:]]//g

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

精彩评论

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