日期:2014-05-19 浏览次数:20686 次
String s="'Sorry, I can't go out today!'";
//先把开头和结尾的'以及'前面不是字母的以及除了'外的其它标点符号先替换掉,再用空白字符进行分割
String[] sArray=s.replaceAll("^'+
------解决方案--------------------
'+$
------解决方案--------------------
(?<![A-Za-z])'+
------解决方案--------------------
[\\p{Punct}&&[^']]+","").split("\\s+");
System.out.println(sArray.length);
for(String str:sArray)
System.out.println(str);
Pattern p = Pattern.compile("'
------解决方案--------------------
,");
Matcher m = p.matcher("'Sorry, I can't go out today!'");
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, "");
}
m.appendTail(sb);
System.out.println(sb.toString());