String.replaceAll() is not working

后端 未结 6 1621
野趣味
野趣味 2020-12-03 13:45

I am editing some email that got from tesseract ocr.

Here is my code:

 if (email != null) {
        email = email.replaceAll(\" \",         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 14:27

    I think you are not aware that first parameter of replaceAll is regex.

    . , |, } might be interpreted in a different way from your expectation.

    .   Any character (may or may not match line terminators)
    

    http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html

    For space you better use

    \s  A whitespace character: [ \t\n\x0B\f\r]
    

    and escape other special characters with a leading \\

提交回复
热议问题