日期:2014-05-20  浏览次数:20635 次

正则表达式求教
将字符串 the boy plays the good games 在the和good处分割

String str = "the boy plays the good games ";
str.split("regex"),不知道这个regex该怎么写

我要的效果是[the,boy plays the,good,games]

------解决方案--------------------
str.split("(?<=the)\\s
------解决方案--------------------
(?<=good)\\s");
------解决方案--------------------
(?<=(the
------解决方案--------------------
good)\\s+)
------解决方案--------------------
引用:
str.split("(?<=the)\\s
------解决方案--------------------
(?<=good)\\s");

帮你改了一下,
String s=str.replaceAll("\\s(?=boy)
------解决方案--------------------
\\s(?=good)
------解决方案--------------------
\\s(?=games)", ",");
------解决方案--------------------
看楼主的意思不仅要把the和good处分割而是想要把the这个和后面的单词分割开来啊。

String str = "the boy plays the good games ";
String[] strs=str.split("(?<=the)\\b+");
System.out.println(Arrays.toString(strs));