import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Main
{
private static final Pattern pattern = Pattern.compile (" +?on.*$", Pattern.MULTILINE);
public static void main (String[]args)
{
final String string = "Posted by ona'je Monday on 29 Feb 2020\n"
+ "Posted by ondrej on 29 Feb 2020";
final String subst = "";
final Matcher matcher = pattern.matcher (string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll (subst);
System.out.println (result);
}
}