PHP - Removing Duplicate Punctuation?

BexBatavola

New Member
Suppose you have the following string: \[code\]Hello... how are you!!?? I'm bored!!\[/code\]I want back-to-back punctuation to be removed wherever possible, and for question marks to be retained in the event of a situation similar to "!?". The filtered string should appear as follows:\[code\]Hello. how are you? I'm bored!\[/code\]Best answer goes to the most concise solution that solves this problem. I expect regular expressions will be the best way to go about solving this, but my knowledge of regular expressions is very, very limited at best, and I have no idea how to go about solving this. I'm more than fine with non-regex solutions, however! An explanation of any code you provide--unless devilishly simple--would also be nice.Thank you!
 
Back
Top