I have an email for eg - john.doe@ny.ps.com or john.doe@ma.ps.com and I want to replace it with john.doe@ps.com for all the emails specifically If they have a prefix before ps.
So far I tried
final String string = "john.doe@ny.ps.com";
final Pattern pattern = Pattern.compile("\\@[^.ps]*");
final Matcher matcher = pattern.matcher(string);
final String result = matcher.replaceAll("");
But the final result is john.doe.ps.com and not john.doe@ps.com