代码:
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
请纠正我。