次のコードを検討してください。
import java.util.regex.*;
public class Pattern3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Pattern p = Pattern.compile("Our"); //line 1
Matcher m = p.matcher("Our mom and Our dad"); //line 2
//p.compile(mom); commented line
StringBuffer s = new StringBuffer();
boolean found = m.find();
while (found){
m.appendReplacement(s, "My"); //line 3
found=m.find();
}
m.appendTail(s); //line 4
System.out.println(s);
}
}
m.appendTrail(s)
a)切り捨てられていない文字列を取得するために 4 行目を呼び出す必要があるのはなぜですか?
"mom"
b) コメントを外して新しい正規表現として配置しても、出力が変わらないのはなぜですか?