「Java」matcher.find()の使い方
Javaコード
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MatcherDemo {
public static void main(String[] args) {
String strOo = “BB XXX PP BB QQQ BBB ZZ";
String string = “BB";
Pattern pattern = Pattern.compile(string);
Matcher matcher = pattern.matcher(strOo);
while(matcher.find()) {
System.out.println(“Found at: “+ matcher.start()+
" – " + matcher.end());
}
}
}
結果
Found at: 0 – 2
Found at: 10 – 12
Found at: 17 – 19