コードコピーは次のとおりです。
パッケージcom.hongyuan.test;
java.util.regex.matcherをインポートします。
java.util.regex.patternをインポートします。
パブリッククラスregextest {
public static void main(string [] args){
string str = "<html> <head> <title> regexテスト</title> </head> <body> <p>これは単純なregexテスト</p> </body> </html>";
//文字列を分割します
string [] splittr = pattern.compile( "[</?|>]")。split(str);
for(int i = 0; i <splitstr.length; i ++){
system.out.print(splittr [i]+"");
}
System.out.println();
//文字列が式パターンと一致するかどうかを判断します
boolean ismatching = pattern.compile( "^<(// w*)>。*</// 1> $")。matcher(str).matches();
system.out.println(ismatching);
//文字列を交換します
string repstr = pattern.compile( "<(/?)p>")。matcher(str).replaceall( "<$ 1h1>");
System.out.println(repstr);
//文字列を抽出します
matcher m = pattern.compile( "<title>(。*)</title>")。matcher(str);
while(m.find()){
System.out.println(M.Group(1));
}
}
}