fork download
  1. using namespace std;
  2. #include <iostream>
  3. #include <string>
  4. #include <regex>
  5. #include <iterator>
  6.  
  7. string escape( string s ) {
  8. std::regex re ( "[\\[\\]\\/^$.|?*+(){}]" );
  9. return std::regex_replace (s, re, "\\$0");
  10. };
  11.  
  12. int main ()
  13. {
  14. cout << escape( "[]abc{}" );
  15. return 0;
  16. }
Success #stdin #stdout 0s 3560KB
stdin
Standard input is empty
stdout
\[\]abc\{\}