Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost-users Digest, Vol 3673, Issue 1
From: Larry (lknain_at_[hidden])
Date: 2014-01-04 08:02:16


Thanks Markus. I did a similar exrcise at John's suggestion.

Alas, there was a bug elsewhere. There are many patterns (>200) and they get
organized by
the first character of the pattern. The organization accounted for the '^'
but not for the
'(' in a "^(...." pattern.

I could not believe it was regex but perhaps I missed something about
patterns as I am not
really a regex person. And sure enough, it was not regex and it was
something about the
patterns but in my code - a failure to organize the patterns correctly.

Larry

-----Original Message-----
From: Markus Lenger
Sent: Saturday, January 04, 2014 4:49 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Boost-users Digest, Vol 3673, Issue 1

Hi Larry!

The error must be somewhere else in your code. The following program
behaves exactly as expected:

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

int main()
{
    boost::match_results<std::string::const_iterator> match;
    boost::match_flag_type flags = boost::match_default;
    boost::regex re(std::string("^XXX_(\\d{3})_\\d{3}$"),
boost::regex::perl | boost::regex::icase);

    std::string the_text = "XXX_123_456";
    bool rc = boost::regex_search(the_text,match,re,flags);
    if (rc)
    {
        std::cout << "Number is " << match[1] << std::endl;
        return 0;
    }
    std::cout << "No match found" << std::endl;
    return 1;
}

---------

max_at_switters:~/tmp$ g++ test_regex.cpp -l boost_regex
max_at_switters:~/tmp$ ./a.out
Number is 123

Am 2014-01-03 18:00, schrieb boost-users-request_at_[hidden]:
> Message: 1
> Date: Thu, 2 Jan 2014 16:40:55 -0500
> From: "Larry" <lknain_at_[hidden]>
> To: <boost-users_at_[hidden]>
> Subject: [Boost-users] [Regex] Subexpression matching during search
> Message-ID: <D06A753E760144CDA0A00B03E0D0DFEE_at_XV2W>
> Content-Type: text/plain; charset="utf-8"
>
> I have probably missed something in the doc that answers my query but I
> just can?t see it.
>
> This is using Perl syntax.
>
> I had a regex:
>
> ^(XXX_\d{3,3})_\d{3,3}$
>
> It compiles OK but does not match anything in a regex_search. If I remove
> the parenthesis
>
> ^XXX_\d{3,3}_\d{3,3}$
>
> I get matches. Any clues as to what I am missing?
>
>
> Extract of regex related code lines:
>
> reg.regex = new boost::regex(reg.reg,boost::regex::perl |
> boost::regex::icase);
>
> boost::match_results<string::const_iterator> match;
> boost::match_flag_type flags = boost::match_default;
> std::string::const_iterator xstart, xend;
>
> xrc =
> boost::regex_search(xstart,xend,match,*((*rgi).regex),flags);
>
> Larry

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net