For example...
String s = "abcxyzabcxyz";
s.replaceAll("xyz", "---");
This would normally give me "abc---abc---". How would I get it to give me "---xyz---xyz" instead?
String#replaceAll accepts a regex, if I understood you correctly, you can use:
s.replaceAll("[^xyz]", "---")
Explanation:
[^xyz] means any character that's not one of "x", "y" or "z".
In order to negate "xyz" as a series, use:
^(?!.*xyz).*$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With