Just ensure that if you need to replace the literal `-`, it is always either at the start or at the end of the replacement set. For e.g. `txt.replaceAll("[- _?]", "*")` works, `txt.replaceAll("[ _?-]", "*")` also works but `txt.replaceAll("[ _-?]", "*")` doesn't. Read More
You can also escape the literal `-`
System.out.println("This is _ a - test?.".replaceAll("[_\\-?]", "+"));
This is + a + test+.
But, including it at the front or end looks cleaner. ;-) Read More
> If you have a handy link to some suitable reference I'd appreciate it, if not don't worry, I'll find it myself.
The reason is that hyphen (or dash) character has a special meaning when used inside a character class (i.e. stuff between the square brackets) which is basically specifying … Read More
> But, including it at the front or end looks cleaner. ;-)
The irony of this whole thing is that I was convinced it was the ? that was the problem, and totally forgot the - is also a special character.
Because I'm obsessed with readablilty/understandability I actually settled on … Read More
That means one or more of the preceding character (class). I.E. There must be at least one of the preceding character (class), but there can also be more than one, and, if there is more, than all of them will be matched. Read More