日期:2014-05-20 浏览次数:20769 次
public static void main(String[] args) { String[] ss = { "ksu<a001>sdf<a002>", "dd<a001>dsdf<sdf", "dsdf<dsfsaf<a001>","sdfadf<<a001>sdfsf<>sdfdfa<sdfasdfadf>>sdiep>" }; String s1 = "(<\\w{0,}>)"; Pattern p = Pattern.compile(s1); for (String s : ss) { System.out.println("=========="); //找到<>,<a001>格式的字符串 Matcher m = p.matcher(s); int point = 0; while (m.find()) { int start = m.start(); int end = m.end(); if (point == start) { System.out.println(); } else { System.out.println(s.substring(point,start)); } System.out.println(m.group()); point = end; } if (point != s.length()) { System.out.println(s.substring(point,s.length())); } } }