RE validation in Java EE(java.util.regex.Pattern)

java.util.regex.Pattern

Object pattern is a regular expression compiler representation. Pattern no public class constructor. To create a Pattern object, you must first call its public static compile method that returns a Pattern object. The method accepts a regular expression as its first parameter.

Pattern class are the two most common methods:

(. 1) = Boolean IsMatch Pattern.matches ( "regExp", "String");
The matches () method of a regular expression matches regExp string string, Match returns true, return false mismatch

Note: String class has matches () method, such as "abcd" .matches (regExp), in fact, two of them are equivalent, String class matches () method is called Pattern.matches () method:

(2) the Pattern of Pattern.compile pattern = ( "regExp");
the compile () method to compile this regular expression represented regExp, returns regExp pattern after being compiled

Guess you like

Origin www.cnblogs.com/maye123/p/10945626.html