我有一些格式相似的字符串。
例如,这是一个字符串:{-LSAy4puffjfgly_2a = {name = user,id = -LSAy4puffjfgly_2a,comment = test ..,userid = E4npergg5_ioeUr2}}
在这里,我想从每个字符串中获取名称和评论。
我正在做什么:
Pattern pattern = Pattern.compile(".*name=(.*),.*comment=(.*),");
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
//toast for name using matcher.group(1)
//toast for comment using matcher.group(2)
但是对于第一次敬酒,我得到的是“用户,id = -LSAy4puffjfgly_2a”作为输出。
对代码进行任何固定,以便仅获取名称(该字符串的用户)。
P.S。-每个字符串的名称,ID,注释和用户ID均不同,且长度不同。所以我不会使用字符串长度操作获取任何子字符串。