2017-09-27 50 views
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試過,我想[]應該有表達,我想表達的字符串開頭並接受所有符號,數字,應有盡有,用[] {}()也

回答

相關問題