(1) pattern Pt = pattern. Compile ("</S * body [^>] *> .*? </S */body/S *> ", pattern. case_insensitive | pattern. dotall );
Matcher Mt = pt. matcher (htmlcontent );
While (mt. Find ()){
String content = Mt. Group ();
Content = content. replaceall ("</S * body [^>] *> ",""). replaceall ("</S */body/S *> ",""). replaceall ("/R |/N ","");
If (content. matches ("// s * (</S * P [^>] *>) * (& nbsp;) * // s * (null) * // s * (& nbsp;) * (</S */P>) * // s *"))
Return true;
}
Use the following statement:
(2) pattern Pt = pattern. Compile ("</S * body [^>] *> (. |/n |/R )*? </S */body/S *> ", pattern. case_insensitive );
Matcher Mt = pt. matcher (htmlcontent );
While (mt. Find ()){
String content = Mt. Group ();
Content = content. replaceall ("</S * body [^>] *> ",""). replaceall ("</S */body/S *> ",""). replaceall ("/R |/N ","");
If (content. matches ("// s * (</S * P [^>] *>) * (& nbsp;) * // s * (null) * // s * (& nbsp;) * (</S */P>) * // s *"))
Return true;
}
But the content is large enough, because Mt. Group (); uses recursive queries to conform to regular characters, but (. |/n |/R )*? By searching through three branches, when the content is large enough
Memory overflow occurs when the memory size is insufficient. Therefore, regular matching with the expression (1) can improve the performance without causing memory overflow.
Pattern. case_insensitive -- enable case-insensitive matching. (? I)
Pattern. Comments -- allow blank spaces and comments in the mode. (? X)
Pattern. dotall -- enable the dotall mode. In dotall mode, expression. Matches any character, including the line terminator. By default, this expression does not match the line terminator. (? S)
Pattern. Literal -- enable mode literal parsing. When this flag is specified, the input string in the specified mode is treated as a string of literal characters. Metacharacter in the input sequence or transfer
The sequence has no special meaning. When used with this flag, the flag case_insensitive and unicode_case reserve their impact on matching.
Pattern. multiline -- enable multiline mode. In multi-row mode, the expressions ^ and $ are just before or after the row terminator or the end of the input sequence. By default, these expressions only match the beginning and end of the entire input sequence. You can also embed a flag expression (? M) Start the multiline mode.
Embedded flag expression
|
Regular
Quantity |
Equivalent embedding sign expression |
|
Pattern. canon_eq |
None |
|
Pattern. case_insensitive |
(? I) |
|
Pattern. Comments |
(? X) |
|
Pattern. multiline |
(? M) |
|
Pattern. dotall |
(? S) |
|
Pattern. Literal |
None |
|
Pattern. unicode_case |
(? U) |
|
Pattern. unix_lines |
(? D) |