参考
記述例
Main.java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
static final String text = "Sample Text hoge Hellow World piyo and hoge Good-bye World piyo";
public static void main(String args[]) throws Exception {
Pattern p1 = Pattern.compile("hoge");
Pattern p2 = Pattern.compile("piyo");
Matcher m1 = p1.matcher(text);
Matcher m2 = p2.matcher(text);
while (m1.find() && m2.find()) {
System.out.println(text.substring(m1.end(), m2.start()));
}
}
}
Hellow World
Good-bye World