#include <iostream>
#include <regex>
#include <string>
bool includeDollarSymbolText(const std::string& input) {
// Regex to match $word$
std::regex pattern("\\$[a-z]+\\$", std::regex_constants::icase);
std::string text = std::regex_replace(input, pattern, "");
// Search for remaining dollar symbols
if (text.find('$') != std::string::npos) {
return false;
}
return true;
}
int main() {
std::cout << std::boolalpha; // Print true/false instead of 1/0
std::cout << includeDollarSymbolText("abc xy $text$ z") << "\n"; // ok
std::cout << includeDollarSymbolText("abc xy $ text$ z") << "\n"; // space
std::cout << includeDollarSymbolText("abc xy $$ z") << "\n"; // empty
std::cout << includeDollarSymbolText("abc 100 $text$ z") << "\n";; // ok
std::cout << includeDollarSymbolText("abc $1000 $text$ z") << "\n"; // open $
std::cout << includeDollarSymbolText("abc xy $IBM$ z $Microsoft$") << "\n"; // ok
std::cout << includeDollarSymbolText("abc xy $F3$ z") << "\n"; // include number
std::cout << includeDollarSymbolText("abc xy $text z") << "\n"; // missing close $
}
/*
run:
true
false
false
true
false
true
false
false
*/