//上面一串等于下面一句
boolean b = Pattern.compile("a*b").matcher("aaaab").matches();
//还有更加精炼的版本:
boolean b = Pattern.matches("a*b","aaaab");
附上API文档:
static Patterncompile(String regex, int flags)
Compiles the given regular expression into a pattern with the given flags.
static booleanmatches(String regex, CharSequence input)
Compiles the given regular expression and attempts to match the given input against it.
都是简化步骤的方法。
boolean b = Pattern.compile("a*b").matcher("aaaab").matches();
//还有更加精炼的版本:
boolean b = Pattern.matches("a*b","aaaab");
附上API文档:
static Patterncompile(String regex, int flags)
Compiles the given regular expression into a pattern with the given flags.
static booleanmatches(String regex, CharSequence input)
Compiles the given regular expression and attempts to match the given input against it.
都是简化步骤的方法。