以下代码始终打印“否”。有任何想法吗 ?
import java.util.*;
import java.lang.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Rextester
{
public static void main(String args[])
{
String field= "superCategory(code)[composite={catalog: $catalog}]";
Pattern FULL_PATTERN = Pattern
.compile("\\[composite\\s*=\\s*\\{([^)]+)\\}\\]");
final Matcher matcher = FULL_PATTERN.matcher(field);
if (matcher.matches()) {
System.out.println("yes");
} else {
System.out.println("no");
}
}
}
答案 0 :(得分:0)
您应该find
模式,而不是matches
:
if (matcher.find()) {