本帖最后由 wenbaoxing 于 2013-10-24 15:17 编辑
- <div class="blockcode"><blockquote>package com.itheima.regular;
- public class Test1 {
- /**
- * @正则表达式切割演示
- */
- public static void main(String[] args) {
- // ----------切割----------
- String str1 = "zhangsan lisi wangwu zhaoliu";
- String str2 = "zhangsan.lisi.wangwu.zhaoliu";
- System.out.println("str1的结果:");
- splitDemo(str1, " +|\\.");
- System.out.println("str2的结果:");
- splitDemo(str2, " +|\\.");
- String strsp = "erkktyqqquizzzzzo";
- System.out.println("按叠词切:");
- splitDemo(strsp, "(.)\\1+");
- }
- // 切割
- // 切割带空格或点的字符串
- public static void splitDemo(String str, String reg) {
- String[] arr = str.split(reg);
- System.out.println("长度为:" + arr.length);
- for (String s : arr) {
- System.out.println(s);
- }
- }
- }
复制代码 以上代码当中前两个正则还能理解,这个正则表达式不太理解,劳烦哪位高手解答一下:splitDemo(strsp, "(.)\\1+");
|