String.split(String regex)符号避免

时间:2016-10-15 16:43:51

标签: java regex string split

我有

String text2 = "Samaras did something by Papandreou's government.";

当我使用

String[] w2 = text2.split("\\s+");

它需要" Papandreou"作为一个整体的词(正如它应该做的那样)。但是,我怎么能避免这个词之后的's

1 个答案:

答案 0 :(得分:0)

text2.split("(\\'s)?\\s+");

This regular expression splits the 's as optional, so it means either "Split 's follow with spaces" or "Split only spaces".