字符串如下所示:
U#:zhang_san#:ASSIGN#:2#:0#:0#:0#:#:#:#:#;U#:wang_wu#:ASSIGN#:2#:0#:0#:0#:#:#:#:#;
我想把zhang_san和wang_wu截取出来
------解决方案--------------------
- Java code
String text = "U#:zhang_san#:ASSIGN#:2#:0#:0#:0#:#:#:#:#;U#:wang_wu#:ASSIGN#:2#:0#:0#:0#:#:#:#:#;"; Matcher m = Pattern.compile("U#:([^#]+)#").matcher(text); StringBuilder sb = new StringBuilder(); while(m.find()){ sb.append(m.group(1)).append(":"); } if(sb.length()>1) sb.deleteCharAt(sb.length()-1); System.out.println(sb.toString());
------解决方案--------------------