public static void test3(){
String a = "fafa[hello.exe]";
Pattern p = Pattern.compile("\\[.+\\]");
Matcher m = p.matcher(a);
boolean b = m.matches();
System.out.println(b);
}显示的false 可是明明是可以匹配的啊.
String a = "fafa[hello.exe]";
Pattern p = Pattern.compile("\\[.+\\]");
Matcher m = p.matcher(a);
boolean b = m.matches();
System.out.println(b);
}显示的false 可是明明是可以匹配的啊.
String a = "fafa[hello.exe]";
Pattern p = Pattern.compile("\\w+\\[(.+)\\]");
Matcher m = p.matcher(a);
boolean b = m.matches();
System.out.println(b);
System.out.println(m.group(1));
至于取值,如LS所说,用()配合group取值
Pattern p = Pattern.compile("\\[(.+)\\]");
Matcher m = p.matcher(a);while(m.find())
{
System.out.println(m.group(1));
}