可以把=号及以后的信息替换为你想要的任意信息
示例二:
public static void main(String[] args) throws Exception{
String filetext = "张小名=25分|李小花=43分|王力=100分|";
Pattern p = Pattern.compile("\\=(.*?)\\|");//正则表达式,取=和|之间的字符串,不包括=和|
Matcher m = p.matcher(filetext);
while(m.find()) {
System.out.println(m.group(1));//m.group(1)不包括这两个字符
}
}
输出结果
25分
43分
100分
示例三:
字符串为"EnterCount":1,"RongYuScore":100,"TiWU":20,"RongYuScore":2,"BluePeg":2,"YellowNewGift":2,"YellowGrow30Gift":2,"CardStar":10}
要去掉"RongYuScore"100, "RongYuScore"2,
public static String test(String a){
Pattern pattern = Pattern.compile("(\"RongYuScore\":[0-9]{0,10},)");
Matcher matcher = pattern
.matcher(a);
while (matcher.find()) {
String c = matcher.group();
// System.out.println(c+"*****");
a = a.replace(c, "");
break;
}
return a;
}
示例四:
filetext =' {"firstVOMap":{"Level":{"1":{"targetLevel":1,"merId":500238,"getDate":1381895683515}}},"scoreVOMap":{"500238":{"merId":500238,"score":14,"fightForce":46054}}} '
private void merLst (String filetext){
// "merId":500238, 要取出500238
Pattern p = Pattern.compile("merId\":(.*?)\\,");//正则表达式,取merId":和,之间的数字
Matcher m = p.matcher(filetext);
while(m.find()) {
System.out.println(m.group(1));//m.group(1)不包括这两个字符
}
}
结果为
500238
500238