Reputation: 1826
I need to use Apache's StringUtils.replaceEach()
method for replacing set of strings. However, this methods also replaces substrings in the word. I know I can use replaceAll
method with \b
regex. But I wanted to know if there's a way to tell StringUtils
to not replace substrings.
Thanks in advance,
Upvotes: 0
Views: 1263
Reputation: 1614
Don't think there's a flag for StringUtils
but one possible hack would be to surround your replacement set with spaces. So instead of "foo" -> "bar"
, you'd have " foo " -> " bar "
. This sadly isn't very helpful if your input may have new lines etc. instead of just spaces between words.
Upvotes: 0
Reputation: 11896
You can try StringUtils.repeat()
, more info can be found to github.
Upvotes: 0