将字符串 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]

解决方案 »

  1.   

    String str = "the boy plays the good games ";
    String replaceAll = str.replaceAll("(the) ","$1,");
    System.out.println(replaceAll);
      

  2.   

    str.split("(?<=the)\\s|(?<=good)\\s");
      

  3.   

    帮你改了一下,
    String s=str.replaceAll("\\s(?=boy)|\\s(?=good)|\\s(?=games)", ",");
      

  4.   

    看楼主的意思不仅要把the和good处分割而是想要把the这个和后面的单词分割开来啊。String str = "the boy plays the good games ";
    String[] strs=str.split("(?<=the)\\b+");
    System.out.println(Arrays.toString(strs));