コード:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
public static void main(String[] args) {
String data = ". Shyam and you. Lakshmi and you. Ram and you. Raju and you. ";
Pattern pattern = Pattern.compile("\\.\\s(.*?and.*?)\\.\\s");
Matcher matcher = pattern.matcher(data);
while (matcher.find()) {
System.out.println(matcher.group(1));
}
}
}
期待される出力:
Shyam and you
Lakshmi and you
Ram and you
Raju and you
しかし、私が得た出力は次のとおりです。
Shyam and you
Ram and you
私を修正してください。