views:

74

answers:

1

I want to write a program in c++ that get a sentence and insert a space between each word and punctuation in it! in sed script this is done with this expression:

sed -e "s/,\([^0-9]\)/ , \1/g" -e "s/\.\([^0-9]\)/ . \1/g" -e 's/\.[ ]*$/ ./g' -e "s/\'/ \' /g" -e 's/?/ ?/g' -e 's/\`\`/ `` /g' -e "s/\' \'/''/g" -e 's/(/ ( /g' -e 's/)/ ) /g' -e 's/ \. \([^$]\)/. \1/g' -e "s/\' s/\'s/g" -e "s/\"\([^\"]*\)\"/\" \1 \"/g" $1 | sed -e "s/\"\([^\"]*\)\"/\`\`\1''/g" 

But I don't khow how i should do this in c++ in windows! for example: should convert a "The question now: Can he act more like hard-charging Teddy Roosevelt." must be converted to "The question now : Can he act more like hard-charging Teddy Roosevelt ." So a punctuation such as '-' or for example a '.' in "No." should not spacing in a sentence, but other punctuation that don't rely on a word or a phrase should be spaced.

+3  A: 

Since you already know how to handle this using regular expressions I think you can try to use Boost.Regex in order to archive the same with C++.

skwllsp
Can you help me what function in boost.regex can do this?It's very complicated sed script, and I am a beginner in regular expression!
Yadollah
Take a look at `boost::regex_replace`
skwllsp