I have a string formatting questions which I think would be best to do with Regular Expressions. Therefore I was hoping I could get advice and help on putting together the set of regex and in which order so one would not cancel or override the other.
Here are the requirements:
1) I need to add only one blank space before and after punctuation signs such as .
, ,
, ;
, :
, !
, ?
, -
, _
, ...
.
So that the following sentence
"Instructions: Pay-attention! Will you? Except with respect to the information specifically incorporated by reference in this Form 10-K, the registrant's definitive proxy statement is not deemed to be filed as a part of this Form 10-K."
Will be:
"Pay - attention ! Will you ? Except with respect to the information specifically incorporated by reference in this Form 10 - K , the registrant's definitive proxy statement is not deemed to be filed as a part of this Form 10 - K ."
2) However, I want to preserve numbers and dollar signs as they are so for instance the number:
1,000.00 has to be 1,000.00 or if it is notated as 1.000,00 has to maintain the same without adding spaces.
Same goes to $1,000.00 which ought to be the same, so $1,000.00.
What is the easiest way to preserve numbers while making sure that the following punctuation marks .
, ,
, ;
, :
, !
, ?
, -
, _
, ...
get a space before and after?
3) On top of that, the third requirement is to make sure that if you have more than 3 dots so .....
they have to be reduced to ...
but if you have 2 dots ..
it has to be reduced to just one dot .
.