#include <iostream>
#include <boost/regex.hpp>int main( int argc, char* argv[] )
{
char *buf="c.addCity(\"4476\",\"北京市朝阳区\")cur.addBoard(new Board(\"CN\",\"3478\",\"浙江\")"; boost::regex exampleregex("(\"[^0-9a-zA-Z,]*\")");
    boost::cmatch result; if(boost::regex_search( buf, result, exampleregex ))
{
std::cout << result << std::endl;
}    return 0;
}
以上代码为何只能输出第一个中文字符串:"北京市朝阳区";
第二个为什么查找不出来?
难道是查找到一个就停止吗,那如何才能使其继续查找?

解决方案 »

  1.   

    你看一下自带的例子.是这样写的.typedef std::map<std::string, int, std::less<std::string> > map_type; boost::regex expression("^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*(<[^;:{]+>[[:space:]]*)?(\\{|:[^;\\{()]*\\{)"); void IndexClasses(map_type& m, const std::string& file) 

       std::string::const_iterator start, end; 
       start = file.begin(); 
       end = file.end(); 
          boost::match_results<std::string::const_iterator> what; 
       boost::match_flag_type flags = boost::match_default; 
       while(regex_search(start, end, what, expression, flags)) 
       { 
          // what[0] contains the whole string 
          // what[5] contains the class name. 
          // what[6] contains the template specialisation if any. 
          // add class name and position to map: 
          m[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] = 
                    what[5].first - file.begin(); 
          // update search position: 
          start = what[0].second; 
          // update flags: 
          flags |= boost::match_prev_avail; 
          flags |= boost::match_not_bob; 
       } 
    }
      

  2.   

    while()
    {
        里面的我看不懂啊;
    }
      

  3.   

    while()
    {
        里面的我看不懂啊;
    }