how to use Boost regular expression replace method?

前端 未结 1 709
不思量自难忘°
不思量自难忘° 2020-12-31 07:41

I have these variables:

boost::regex re //regular expression to use
std::string stringToChange //replace this string
std::string newValue //new value that is         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 08:45

    Here is an example of basic usage:

    #include 
    #include 
    #include 
    
    int main(){
      std::string str = "hellooooooooo";
      std::string newtext = "o Bob";
      boost::regex re("ooooooooo");
      std::cout << str << std::endl;
    
      std::string result = boost::regex_replace(str, re, newtext);
      std::cout << result << std::endl;
    }
    

    Output

    hellooooooooo

    hello Bob

    Make sure you are including and have linked to the boost_regex library.

    0 讨论(0)
提交回复
热议问题