2016-10-14 29 views
-3

我写一个Java程序来删除字符串中的所有标点符号标点符号如何使用正则表达式来删除一个字符串

"1.1 Interactive systems In today's world, interacting with computer-based devices and systems is commonplace." 

如何使用正则表达式来删除标点有这个字符串

"11 Interactive systems In todays world interacting with computerbased devices and systems is commonplace". 
+2

这两句话似乎有什么共同之处彼此?你有问题吗? –

+0

谢谢!我修好了它。 –

回答

0

使用字符串的replaceAll用正则表达式:

String mystring = "\"1.1 Interactive systems In today's world, interacting with computer-based devices and systems is commonplace.\""; 

String replaced = mystring.replaceAll("\\p{Punct}", ""); 

实际的正则表达式是\p{Punct},但我们需要转义\因此是另一个反斜杠。

输出:

11 Interactive systems In todays world interacting with computerbased devices and systems is commonplace 
+1

'\ p {Punct}'已经表示字符集,将它放入另一个字符集'[..]'没有意义(就像使用'[\ d]'而不是简单的'\ d' '),所以你可以从这个正则表达式中去掉'['和']'。顺便说一句,你最后还有''''。 – Pshemo

+0

谢谢你用实例解释!作出更正。 – bits

相关问题