^ and $ do not match line ends by default — they match the beginning and end of the entire string.
Match on whatever begins and ends your lines in a separate grouping from the line content. Then replace the line ends in your substitution expression.
Also, be careful how you match stuff.
• “{1,}” is the same as “+” — matches at least one character.
If I understood you correctly, you indicated leading spaces are ok?
• “.*” is greedy — it will match to the end of the file if it can.
Either be specific about what you match (instead of any character),
or turn off greedy by adding a question mark: “.*?”.
1 2 3 4 5
// Define regex to match lines with comments
staticconst boost::regex re_comment("(^|\n)(\\s*--[^\n|$]*)(\n|$)", boost::regex::extended);
// Replace via regex replace
std::string result = boost::regex_replace(readText, re_comment, "\\1 \\3");