Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c++;促进 我想在字符串中做两个替换,我知道如何在PHP中编写正则表达式,我对C++ Boost不太熟悉。 // Replace all doubled-up <BR> tags with <P> tags, and remove fonts. $string = preg_replace("/<br\/?>[ \r\n\s]*<br\/?>/i", "</p><p>", $string); $string = preg_replace("/<\/?font[^>]*>/i", "", $string); //用标记替换所有折叠的标记,并删除字体。 $string=preg\u replace(“/[\r\n\s]*/i”,“_Php_C++_Regex_Boost_Boost Regex - Fatal编程技术网

如何在c++;促进 我想在字符串中做两个替换,我知道如何在PHP中编写正则表达式,我对C++ Boost不太熟悉。 // Replace all doubled-up <BR> tags with <P> tags, and remove fonts. $string = preg_replace("/<br\/?>[ \r\n\s]*<br\/?>/i", "</p><p>", $string); $string = preg_replace("/<\/?font[^>]*>/i", "", $string); //用标记替换所有折叠的标记,并删除字体。 $string=preg\u replace(“/[\r\n\s]*/i”,“

如何在c++;促进 我想在字符串中做两个替换,我知道如何在PHP中编写正则表达式,我对C++ Boost不太熟悉。 // Replace all doubled-up <BR> tags with <P> tags, and remove fonts. $string = preg_replace("/<br\/?>[ \r\n\s]*<br\/?>/i", "</p><p>", $string); $string = preg_replace("/<\/?font[^>]*>/i", "", $string); //用标记替换所有折叠的标记,并删除字体。 $string=preg\u replace(“/[\r\n\s]*/i”,“,php,c++,regex,boost,boost-regex,Php,C++,Regex,Boost,Boost Regex,”,$string); $string=preg_replace(“/]*>/i”,“”,$string); 如何在C++ Boost?中编写代码? 提前谢谢。所有的常规都适用 #包括 #包括 #包括 int main() { boost::regex double\u br(“[\\r\\n\\s]*”,boost::regex::icase); boost::regex字体(“]*>”,boost::regex::icase); std::字符串大小写[]={ “foo酒吧”, “一个两个

”,$string); $string=preg_replace(“/]*>/i”,“”,$string); 如何在C++ Boost?

中编写代码? 提前谢谢。

所有的常规都适用

#包括
#包括
#包括
int main()
{
boost::regex double\u br(“[\\r\\n\\s]*”,boost::regex::icase);
boost::regex字体(“]*>”,boost::regex::icase);
std::字符串大小写[]={
“foo

酒吧”, “一个

两个”, “a

b”, “a

c

d”, “w00t!”, “你好”, "" }; 对于(std::string*s=cases;*s!=“”;++s){ std::cout所有通常的方法都适用

#包括
#包括
#包括
int main()
{
boost::regex double\u br(“[\\r\\n\\s]*”,boost::regex::icase);
boost::regex字体(“]*>”,boost::regex::icase);
std::字符串大小写[]={
“foo

酒吧”, “一个

两个”, “a

b”, “a

c

d”, “w00t!”, “你好”, "" }; 对于(std::string*s=cases;*s!=“”;++s){
很好,您尝试过了吗?您遇到了什么错误/问题?这些正则表达式可以工作,但您需要双重转义正则表达式转义字符(例如。\r应该是\\r)你需要这个,因为它恰好也是C++中的字符串转义符。我使用了双转义字符,但它没有替换任何东西……嗯,你试过了吗?你得到什么错误/问题?这些正则表达式会起作用,但是你需要双解你的正则表达式转义字符(例如\r应该是\r)。你需要这个,因为它正好也是C++中的字符串转义符。我使用了双转义字符,并尝试了,但是它没有替换任何东西…
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
  boost::regex double_br("<br/?>[ \\r\\n\\s]*<br/?>", boost::regex::icase);
  boost::regex fonts("</?font[^>]*>", boost::regex::icase);

  std::string cases[] = {
    "foo<br><br>bar",
    "one<br/><br>two",
    "a<br>   <br/>b",
    "a<br><br>c<br/><br/>d",
    "<font attr=\"value\">w00t!</font>",
    "<font attr=\"value\">hello</font><font>bye</font>",
    ""
  };

  for (std::string *s = cases; *s != ""; ++s) {
    std::cout << *s << ":\n";

    std::string result;
    result = boost::regex_replace(*s, double_br, "</p><p>");
    result = boost::regex_replace(result, fonts, "");

    std::cout << "  - [" << result << "]\n";
  }

  return 0;
}
foo<br><br>bar: - [foo</p><p>bar] one<br/><br>two: - [one</p><p>two] a<br> <br/>b: - [a</p><p>b] a<br><br>c<br/><br/>d: - [a</p><p>c</p><p>d] <font attr="value">w00t!</font>: - [w00t!] <font attr="value">hello</font><font>bye</font>: - [hellobye]