Java.util.regex.Pattern
A compiled implementation of a regular expression.
Regular expressions usually appear as strings, which must first be compiled into an instance of the pattern class.
The result model can be used to generate a matcher, which (the generated Macher instance) can match the base
Any sequence of characters generated by this regular expression. When you implement a match in a match, you include the
Any number of cases, and multiple matches can share the same pattern.
The following is a typical invocation order:
Pattern p = pattern.compile ("A*b");
Matcher m = P.matcher ("Aaaaab");
Boolean B = m.matches ();
For ease of use, the pattern class also defines the matches () method,
Because sometimes a regular expression makes it only once.
In one call, this method first compiles the expression and then matches the input sequence.
The following sentence:
Boolean B = pattern.matches ("A*b", "Aaaaab");
Equivalent to the above three sentences. But since it does not allow subsequent patterns to be reused, duplicate matches are required
is obviously less efficient than the above method.
Instances of the pattern class cannot be changed and are thread-safe. Note that the Matcher class is not thread-safe
。
public static void Main (string[] args) {
String str = "Aaaaaaaaaaaaww
Wwwwwwwwwwwwwwwwwwwww
Wwwwwwwwwwwwwwwwwwwwww
Wwwwwwwwwwwwwwwwwwwwwww
Wwwwwwwwwwwwwwwwwwwwwww
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ";
Pattern PA;
Matcher Ma;
PA = pattern
. Compile ("<meta.*?name.*?=.*?/". *? description.*?/". *content.*?=.*?/");
Ma = pa.matcher (str);
if (Ma.find ()) {
System.out.println ("-----");
System.out.println (Ma.group ());
} else {
System.out.println ("No matching string");
}
}