当前位置: 代码迷 >> JavaScript >> 正则地图和json
  详细解决方案

正则地图和json

热度:104   发布时间:2012-12-20 09:53:21.0
正则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);
	}
?
  相关解决方案