1-line matching
2. It does not start with XX, for example, it does not start with www.
3 Case insensitive
4. Two units or operations, such as www & brvbar; 3 w.
Q:
1: multi-row matching
By default, the line terminator cannot be matched. (there are 6 line terminators. For details, see the Pattern api doc)
Similarly, you can use the compile parameter Pattern. DOTALL as the case does not match.
If it is case sensitive, add the Pattern. CASE_INSENSITIVE mentioned above. For example:
Import java. util. regex. Matcher;
Import java. util. regex. Pattern; public class Test {
Public static void main (String [] args ){
String str =
"<Table> n" +
"<Tr> n" +
"<Td> n" +
"Hello World! N "+
"</Td> n" +
"</Tr> n" +
"</Table> ";
String regex = "<td> (. + ?) </Td> ";
Pattern pattern = Pattern. compile (regex );
Matcher matcher = pattern. matcher (str );
While (matcher. find ()){
System. out. println (matcher. group (1). trim ());
}
}
}
Code 2
Import java. util. regex. Matcher;
Import java. util. regex. Pattern; public class Test {
Public static void main (String [] args ){
String str =
"<Table> n" +
"<Tr> n" +
"<Td> n" +
"Hello World! N "+
"</Td> n" +
"</Tr> n" +
"</Table> ";
String regex = "<td> (. + ?) </Td> ";
Pattern pattern = Pattern. compile (regex );
Matcher matcher = pattern. matcher (str );
While (matcher. find ()){
System. out. println (matcher. group (1). trim ());
}
}
}