日期:2014-05-16  浏览次数:20382 次

正则map和json?
public void testOne() {
		Set<String> set = new HashSet();
		Pattern p = Pattern.compile("[{,](.+?)[=]");
		Pattern p1 = Pattern.compile("[=]([^\\[]+?)[\\},]");
		Matcher matcher = p.matcher(m);
		Matcher matcher1 = p1.matcher(m);
		while (matcher.find()) {
			System.out.println(matcher.group(1));
			set.add(matcher.group(1).trim());
		}
		while (matcher1.find()) {
			System.out.println(matcher1.group(1));
			set.add(matcher1.group(1).trim());
		}

		for (String s : set) {
			m = m.replaceAll("\\b"+s+"\\b", "\"" + s + "\"");
		}
		m=m.replaceAll("=", ":");
		System.err.println(m);
	}
?