首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

正则表达式求教,该怎么解决

2013-09-15 
正则表达式求教将字符串 the boy plays the good games 在the和good处分割String str the boy plays th

正则表达式求教
将字符串 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));

热点排行