Re: [Boost-bugs] [Boost C++ Libraries] #4721: multiple capture groups with the same name break regex

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4721: multiple capture groups with the same name break regex
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-10-13 16:58:27


#4721: multiple capture groups with the same name break regex
-------------------------------------+--------------------------------------
  Reporter: robin.snyder@… | Owner: johnmaddock
      Type: Bugs | Status: closed
 Milestone: To Be Determined | Component: regex
   Version: Boost 1.44.0 | Severity: Problem
Resolution: fixed | Keywords: regex named capture group
-------------------------------------+--------------------------------------
Changes (by johnmaddock):

  * status: new => closed
  * resolution: => fixed

Comment:

 Fixed in this changeset: https://svn.boost.org/trac/boost/changeset/65943

 It's rather a large patch, but you would need to apply this to 1.44.0 to
 get this working correctly.

 Named sub-expressions are accessed as before, by subscripting the
 match_results object with the name, here's my test code for your example


 {{{
 void test(const boost::regex& r, const char* text)
 {
    using namespace std;
    boost::cmatch what;
    if(regex_search(text, what, r))
    {
       cout << "The following match was found for text " << text << endl;
       for(unsigned i = 0; i < what.size(); ++i)
       {
          cout << "$" << i << " = \"" << what[i] << "\"" << endl;
       }
       cout << "MPAT01 = " << what["MPAT01"] << endl;
       cout << "MPAT01.zone = " << what["MPAT01.zone"] << endl;
       cout << "MPAT01.band = " << what["MPAT01.band"] << endl;
       cout << "MPAT01.grid = " << what["MPAT01.grid"] << endl;
       cout << "MPAT01.easting = " << what["MPAT01.easting"] << endl;
       cout << "MPAT01.northing = " << what["MPAT01.northing"] << endl;
    }
    else
    {
       cout << "No match found for text " << text << endl;
    }
    cout << endl;
 }


 int _tmain(int argc, _TCHAR* argv[])
 {

    boost::regex
 e("(?<MPAT01>((?<MPAT01.zone>[0-5][0-9]|60)\\s*)((?<MPAT01.band>[CcDdEeFfGgHhJjKkLlMmNnPpQqRrSsTtUuVvWwXx])\\s*)(?<MPAT01.grid>[AaBbCcDdEeFfGgHhJjKkLlMmNnPpQqRrSsTtUuVvWwXxYyZz][AaBbCcDdEeFfGgHhJjKkLlMmNnPpQqRrSsTtUuVv])\\s*(((?<MPAT01.easting>\\d{5})\\s*(?<MPAT01.northing>\\d{5}))|((?<MPAT01.easting>\\d{4})\\s*(?<MPAT01.northing>\\d{4}))|((?<MPAT01.easting>\\d{3})\\s*(?<MPAT01.northing>\\d{3}))))([^\\d]|$)");
    test(e, "11spa 12345 67890");
    test(e, "11spa 1234 6789");
    test(e, "11spa 123 678");
    return 0;
 }


 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4721#comment:6>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC