The code:
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)); } } }
Expected Result:
Shyam and you Lakshmi and you Ram and you Raju and you
But I got a way out:
Shyam and you Ram and you
Please correct me.
source share