开发者

Regex boost library comparing

int array[328];
string array2[328];
int array3[328]; //counter array
int value=0;

std::string text("((1 0) (25 5) (27 2) )((25 5) (27 2) (31 2) )");
boost::regex regex("(\\d)+[^\\d+\\)]"); // [^\\d+] ");


boost::sregex_token_iterator iter(text.begin(), text.end(), regex, 0);
boost::sregex_token_iterator end;


for( ; iter != end; ++iter )
{
    std::cout<<*iter<<"\n";


    for(int b=0; b<328; b++)
      {
        if(*iter == "1")
          {
            cout << "yes\n";
    开发者_开发百科        array3[b] = array3[b]+ count;
            break;
          }
      }
}

return 0;}

We are using the boost library to make regular expressions to see how many times the 1, 25 27 and 31 appears in other words just the fist numbers after the parenthesis. HOwever, we are trying to use an array with the numbers between 1-28 to compare it but we dont know the type of iter to compare if that makes sense.


Both your code and your regex are malformed badly in numerous ways. But beyond this, the fundamental problem you are having is that given how your regex is formed, the match will result in a pair of string::const_iterators, pointing to the beginning and one-past-the-end of the match, respectively.

Change your code to:

    for(int b=0; b<328; b++)
      {
        if(*iter == "1 ")
          {
            cout << "yes\n";
            array3[b] = array3[b]+ count;
            break;
          }
      }
}

...and it will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜