Boost logo

Boost Users :

From: soleani (anibal_at_[hidden])
Date: 2002-06-29 13:29:58


Hi all,

This is the test program:

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

int main()
{
    static const boost::regex regexRedirectedSection( "\\[(.+?)
\\s*=\\s*<(.+?):(.+?)>\\]",
                                                      
boost::regbase::perl );

    std::string input = "[MY_SECTION = <FILE:SECTION>]";

    boost::cmatch what;
    if ( boost::regex_search( input, what, regexRedirectedSection,
boost::regbase::perl ) )
    {
        cerr << "Matched new style section redirection!!!! Input
is: " << input << endl;
        cerr << "0 gives: --" << what[0].first << "-- and second: "
<< what[0].second << endl;
        cerr << "1 gives: --" << what[1].first << "-- and second: "
<< what[1].second << endl;
        cerr << "2 gives: --" << what[2].first << "-- and second: "
<< what[2].second << endl;
        cerr << "3 gives: --" << what[3].first << "-- and second: "
<< what[3].second << endl;
    }

    return 0;
}

This is the output:

[anibal_at_anibal ControlFile]$ ./match
Matched new style section redirection!!!! Input is: [MY_SECTION =
<FILE:SECTION>]
0 gives: --[MY_SECTION = <FILE:SECTION>]-- and second:
1 gives: --MY_SECTION = <FILE:SECTION>]-- and second: =
<FILE:SECTION>]
2 gives: --FILE:SECTION>]-- and second: :SECTION>]
3 gives: --SECTION>]-- and second: >]

I don't understand why $1 is not giving my MY_SECTION only.
It looks like the non-greedy operator is not working as I expect it.
This same expression works in Perl and jakarta's regex engine in Java.

I basically need to extract MY_SECTION, FILE, and SECTION from the
input string.

Any pointers as to what's going on will be greatly appreciated.

-Anibal


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