Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am editing some email that got from tesseract ocr.

Here is my code:

 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;

But the output is not correct.

Input :

amrut=ac.hrworks@g mai|.com

Output :

lalcl.lhlrlwlolrlklsl@lglmlalil|l.lclolml

But when I assigned the result to a new String after every replacement, it works fine. Why continuous assignment in the same String is not working?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

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");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...