日期:2014-05-20  浏览次数:20580 次

关于写正则的问题,求帮忙写个正则
这就是一部分html的代码,我想搜索出来"name":后面引号内的内容,也就是:Adidas阿迪达斯女款运动针织长裤X25189,S
我还想搜索出"price":后的211.00


"mPrice":369.00,"name":"Adidas阿迪达斯女款运动针织长裤X25189,S","onsale":true,"price":221.00,"sku":"20-440-8965","stock":2.00,"styleID":"20-440-8964"


我用了 (?<=exp)  匹配exp后面的位置 可是什么都查不到,能告诉我为什么么?还有应该怎么写才能得到我想要的?

------解决方案--------------------

String str = "\"mPrice\":369.00,\"name\":\"Adidas阿迪达斯女款运动针织长裤X25189,S\",\"onsale\":true,\"price\":221.00,\"sku\":\"20-440-8965\",\"stock\":2.00,\"styleID\":\"20-440-8964\"";

String[] ss = str.replaceAll(".*?\"name\":\"(.*?)\".*?\"price\":(.*?),.*", "$1,$2").split(",");
System.out.println(ss[0]);
System.out.println(ss[1]);

------解决方案--------------------
String t="\"mPrice\":369.00,\"name\":\"Adidas阿迪达斯女款运动针织长裤X25189,S\",\"onsale\":true,\"price\":221.00,\"sku\":\"20-440-8965\",\"stock\":2.00,\"styleID\":\"20-440-8964\"";
  
Matcher m = Pattern.compile("name\":\"(.*?)(?=\",)").matcher(t);
while (m.find()) {
System.out.println(m.group(1));

}

------解决方案--------------------
String t="\"mPrice\":369.00,\"name\":\"Adidas阿迪达斯女款运动针织长裤X25189,S\",\"onsale\":true,\"price\":221.00,\"sku\":\"20-440-8965\",\"stock\":2.00,\"styleID\":\"20-440-8964\"";
Matcher m = Pattern.compile("(name
------解决方案--------------------
price)\":\"?(.*?)(?=\"?,)").matcher(t);
while (m.find()) {
System. err .println(m.group(2));
}