Suppose I have string coming from Input with name (for eg: Mr . Aditya Jha). How do I remove salutation from the start of input?
List of salutations that ca
You may use
name = name.replaceAll("\\s{2,}", " ").replaceFirst("(?i)^\\s*(?:M(?:iss|rs?|s)|Dr|Rev)\\b[\\s.]*", "").trim();
See the regex demo
Pattern details
(?i) - case ignoring option^ - start of string\s* - 0+ whitespaces(?:M(?:iss|rs?|s)|Dr|Rev) - M followed with iss, r, rs, s, or Dr or Rev (you may add more after | here)\b - word boundary[\s.]* - 0 or more whitespaces or dots.