// Using std::regex
#include <iostream>
#include <string>
#include <regex>
// ------------------------------------------------------------
// removeQuotesAndCommas
// Removes single quotes ('), double quotes ("), and commas (,)
// using a regular expression.
// Note: regex is slower, use for simple tasks.
// ------------------------------------------------------------
std::string removeQuotesAndCommas(const std::string& input) {
// Replace any ', ", or , with an empty string
return std::regex_replace(input, std::regex("['\",]"), "");
}
int main() {
std::string s = "\"Imagine there's, no heaven\", 'Imagine' \"all\", the people.";
std::string cleaned = removeQuotesAndCommas(s);
std::cout << "Original: " << s << "\n";
std::cout << "Cleaned: " << cleaned << "\n";
}
/*
run:
Original: "Imagine there's, no heaven", 'Imagine' "all", the people.
Cleaned: Imagine theres no heaven Imagine all the people.
*/