how to use Boost regular expression replace method?

前端 未结 1 698
不思量自难忘°
不思量自难忘° 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 <iostream>
    #include <string>
    #include <boost/regex.hpp>
    
    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 <boost/regex.hpp> and have linked to the boost_regex library.

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