String.replaceAll() is not working for some strings
You have to escape .
by \\.
like following :
if (email != null) {
email = email.replaceAll(" ", "");
email = email.replaceAll("caneer", "career");
email = email.replaceAll("canaer", "career");
email = email.replaceAll("canear", "career");
email = email.replaceAll("caraer", "career");
email = email.replaceAll("carear", "career");
email = email.replace("|", "l");
email = email.replaceAll("}", "j");
email = email.replaceAll("j3b", "job");
email = email.replaceAll("gmaii\\.com", "gmail.com");
email = email.replaceAll("hotmaii\\.com", "hotmail.com");
email = email.replaceAll("\\.c0m", "com");
email = email.replaceAll("\\.coin", "com");
email = email.replaceAll("consuit", "consult");
}
return email;
You'll note in the Javadoc for String.replaceAll() that the first argument is a regular expression.
A period (.
) has a special meaning there as does a pipe (|
) as does a curly brace (}
). You need to escape them all, such as:
email = email.replaceAll("gmaii\\.com", "gmail.com");
By realizing that replaceAll()
first argument is regex
you can make your comparisons much less
For example you can check for possible misspellings of the word career
by the following regex
email = email.replaceAll("ca[n|r][e|a][e|a]r", "career"));
(Is this Java?)
Note that in Java, replaceAll accepts a regular expression and the dot matches any character. You need to escape the dot or use
somestring.replaceAll(Pattern.quote("gmail.com"), "replacement");
Also note the typo here:
email = emai.replaceAll("canear", "career");
should be
email = email.replaceAll("canear", "career");