2

这是一个这样的句子:

Happy birthday!! I have a good day. :)

我想知道如何使用正则表达式将这些句子处理为以下格式:

Happy birthday! I have a good day.
4

1 回答 1

2

以下是如何在 PERL 中执行此操作(因为您没有指定编程语言。

my $str = "Happy birthday!! I have a good day. :)";
$str =~ s/([.!?]){2,}/$1/g;    #remove multiple punctuation
$str =~ s/[:;()]+//g;          #remove emoticon
print $str;
于 2010-10-11T01:42:12.737 回答