Hi everyone,

I'm sure this is embarrassingly simple but I've been at it for too long and I just don't see it. What I'm trying to do is to remove single characters from a string. I.e. in the string 'B comes before c but after a' the single characters must be removed, so that the remaining result is 'comes before but after'.

Now all literature I've seen so far states that \S in a regexp should match a non-whitespace character. However I find that it does not match any special characters in the target string. For example,

echo preg_replace (('/\b\S\b/', '', "B comes before c but after a");
produces the desired

comes before but after
but if the target string contains any of the characters escaped by preg_quote (i.e. \ + * ? [ ^ ] $ ( ) { } = ! < > | : etc... ) these are left in the remaining result:

echo preg_replace (('/\b\S\b/', '', "A { comes } before c ? but : after a !");

{ comes } before ? but : after !
Why is this? Yes, special characters have to be escaped in the regexp or you can expect unpredictable results, but if \S should just match a non-whitespace character (defined as [\t\n\r\f\v] according to the literature) why does it not match ? or ! or any other 'special' character?

And, of course, if I want to remove a single character from a string as I'm trying to do here, what _is_ the proper way to do it?

* Bangs head against wall *