String search="firstName:john doe,";
Pattern pattern = Pattern.compile("(\\w+?)(:|<|>|=)(\\w+?),");
Matcher matcher = pattern.matcher(search+",");
while (matcher.find()) {
System.out.println(matcher.group(1)); //firstName
System.out.println(matcher.group(2)); //:
System.out.println(matcher.group(3)); //john
}
我想要一个正则表达式来匹配字符串john doe,其中包含第3组中的空格:
答案 0 :(得分:0)
假设逗号是名称末尾的标记,我们可以尝试:
String search="firstName:john doe,";
Pattern pattern = Pattern.compile("(\\w+)(:|<|>|=)([^,]+),");
Matcher matcher = pattern.matcher(search);