I have a string
"This is a big sentence . ! ? ! but I have to remove the space ."
In this sentence I want to remove all the space coming before the punctuation and should become
"This is a big sentence.!?! but I have to remove the space."
I am trying to use "\p{Punct}" but not able to replace in string.
You should use positive lookahead:
ideone.com demo for your particular string
Break down of the expression:
\s: White space…(?=\\p{Punct})… which is followed by punctuation.