Opened 12 years ago

Closed 12 years ago

#4837 closed Bugs (worksforme)

referencing subexpr matches via names asserts

Reported by: nis.aggarwal@… Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.40.0 Severity: Showstopper
Keywords: regex named subexpression Cc:

Description

I am using named subexpressions. The regex pattern constructs fine and the matching works fine too but when I try to index into the match_results object using the name, an assertion is thrown.

#include <boost/regex.hpp> 
#include <string> 
#include <iostream> 
#include <stdio.h>

using namespace boost; 

int main()
{
    std::string str = "for is while";

    regex pat("(?<keyword>\\b(for|while)\\b)");
    sregex_iterator match_iter(str.begin(), str.end(), pat);
    sregex_iterator match_end;

    for (; match_iter != match_end; ++match_iter) {
        smatch match = (*match_iter);

        ssub_match keywordMatch = match["keyword"];
        if (keywordMatch.matched) {
            printf("matched a keyword!\n");
        }
        size_t pos = (*match_iter).position((size_t)0);
        size_t len = (*match_iter)[0].second - (*match_iter)[0].first;
        
        std::cout << pos << "," << len << std::endl;
    }

    return 0;
}

Change History (1)

comment:1 by John Maddock, 12 years ago

Resolution: worksforme
Status: newclosed

I'm closing this issue as this works for me with Boost-1.44.0.

Can you please update your Boost installation to the latest release and try again? If it's still failing for you with Boost-1.44, then please reopen and add your platform/compiler information. Some information on where the assertion is failing would also be a big help.

Thanks, John Maddock.

Note: See TracTickets for help on using tickets.