Answer after updated question
The issue with your double pipe was that it will look for matches to replace, and hence replace any single occurrence of something matching the first word ("shoe"), and if it doesn't work look for the next potential match, which is an empty string (between the 2 pipes). So you'd find these matches and replace them (ironically) with empty strings as well. As a match was found for this position, it switches to the next potential positions and doesn't check the other words for that one.
Quite likely, any word after the doubled-pipe was never replaced.
It didn't yield an error because the syntax is valid and there are legitimate cases where you'd want to look for empty strings to insert characters.
Original answer
Kept for similar errors encountered by others.
This obviously works, so there are only a few options left:
- You need to assign the return value (string are immutable in Java, as also mentioned by Ehran)
- There are some non-printable characters in the string;
- There is an encoding issue when you read the input and compare;
- You word is delimited by something that doesn't register a boundary.
- You want a case-insensitive search (use
Pattern.compile(regex, flags).matcher(str).replaceAll(repl) instead, with a CASE_INSENTIVE flag to compile the pattern)
- There's something wrong somewhere else that we cannot see because you give:
- neither the whole code
- nor the input data.
Please provide more code and your input excerpt.
If you read from a socket, do make sure as well that you specify the right headers for your request and that you use valid content type and character encoding. Please make also sure that you are not using a strange encoding on your source files and your input data files.
This is partially re-written off of another answer I gave on this question about why the java String.contains method does not return found matches correctly.