0

I am trying remove a substring following a pattern.

I am trying to use the boost library as it provides the regex_replace, which as I understood should replace every occurence of the regex with my given new string.

std::string s("m_value[0..3]");
boost::regex rgx("\[.*\]");
return boost::regex_replace(s, rgx, "");

This code returns m_value[03] instead of m_value. Any ideas why?

Tituuss10
  • 92
  • 10

1 Answers1

2

You forget to escape the escape.

You need two backslashes to add a backslash in strings:

boost::regex rgx("\\[.*\\]");

Or use raw string literals:

boost::regex rgx(R"(\[.*\])");
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621