1
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Rejex {
public static final String REGEX_CONSTANT="^[a-zA-Z][a-zA-Z0-9&\\-()$#@!^*=|'{}:.%_+?`~<>[]]*$";
public static void main(String[] args) {
System.out.println(validateRegex(REGEX_CONSTANT,"dd[]"));
}
public static boolean validateRegex(String regex, String value)
{
Pattern patternObjects = Pattern.compile(regex);
Matcher matcherObject = patternObjects.matcher(value);
return matcherObject.matches();
}
}
返回FALSE試過,我想[]應該有表達,我想表達的字符串開頭並接受所有符號,數字,應有盡有,用[] {}()也
它工作正常,但它不是\符號除外。 –