A cópia do código é a seguinte:
pacote com.hongyuan.test;
importar java.util.regex.matcher;
importar java.util.regex.pattern;
classe pública regextest {
public static void main (string [] args) {
String str = "<html> <head> <title> regex teste </title> </ad head> <body> <p> Este é um teste regex simples </p> </body> </html>";
// Divida a string
String [] splitstr = padrony.compile ("[</? |>]"). Split (str);
for (int i = 0; i <splitstr.Length; i ++) {
System.out.print (splitstr [i]+"");
}
System.out.println ();
// julga se a string corresponde ao padrão de fórmula
boolean ismatching = padrony.compile ("^<(// w*)>.*</// 1> $"). Matcher (str) .matches ();
System.out.println (isMatching);
// Substitua a string
String repst = padring.compile ("<(/?) P>"). Matcher (str) .replaceall ("<$ 1H1>");
System.out.println (repstr);
// Extrair string
Matcher M = Pattern.compile ("<title> (.*) </ititle>"). Matcher (STR);
while (m.find ()) {
System.out.println (M.Group (1));
}
}
}