想从文本中提取类似格式的数据。。
内容:
resultStatus={9000};memo={1};result={temp}
结果:
resultStatus 9000
memo 1
result temp
对正则不熟悉,麻烦各位XDJM帮帮忙看下~~
先谢谢了~~
------解决方案--------------------------------------------------------
- Java code
public static void main(String[] args) { String s ="resultStatus={9000};memo={1};result={temp}" ; s= s.replaceAll("=", " ") ; s= s.replaceAll("[\\{\\}]", " ") ; String[] ss = s.split(";") ; for (int i = 0; i < ss.length; i++) { System.out.println(ss[i]); }}
------解决方案--------------------------------------------------------
- Java code
String s = "resultStatus={9000};memo={1};result={temp}"; Pattern p = Pattern.compile("([^;]*?)\\=\\{(.*?)\\}"); Matcher m = p.matcher(s); while (m.find()) { System.out.println(m.group(1) + " = " + m.group(2)); }