Does boost's regex lib support the lookbehind feature?

Discussion in 'C++' started by DSmith1974@googlemail.com, Nov 9, 2006.

  1. Guest

    Are lookarounds supported in the boost regex lib? In my VS6 project
    using boost 1.32.0 I can declare a regex as..

    <code_snippet>
    std::wstring wstrFilename = L"01_BAR08";

    boost::wregex regxCarFile( L"(?=BAR)BAR[0-9]{2}" );
    bRet = boost::regex_search( wstrFilename, m, regxCarFile,
    boost::match_default );
    if( true == bRet )
    {
    // No match! never gets here.
    }
    </code_snippet>

    ...hoping to match '08' rather than '01' but boost matches nothing.
    Even worse if I try and declare a regex that uses a lookbehind for e.g.
    'boost::regxCarFile( L"(?<=BAR)[0-9]{2}" )' I get bad_exception thrown
    from boost.

    Are there any plans to support lookarounds in boost, or is there
    another suitable regex library that can handle them?

    Regards,

    Duncan.
     
    , Nov 9, 2006
    #1
    1. Advertising

  2. Pete Becker Guest

    wrote:
    > Are lookarounds supported in the boost regex lib?


    I'm not up on the full details of boost's regex library, but TR1's regex
    library is based on it, and it doesn't support lookahead or lookbehind.
    There are no proposals to add them.

    > In my VS6 project
    > using boost 1.32.0 I can declare a regex as..
    >
    > <code_snippet>
    > std::wstring wstrFilename = L"01_BAR08";
    >
    > boost::wregex regxCarFile( L"(?=BAR)BAR[0-9]{2}" );
    > bRet = boost::regex_search( wstrFilename, m, regxCarFile,


    The assert in this regular expression doesn't add anything.
    L"BAR[0-9]{2}" says the same thing. Of course, it could be that this
    example is oversimplified.

    > boost::match_default );
    > if( true == bRet )
    > {
    > // No match! never gets here.
    > }
    > </code_snippet>
    >
    > ..hoping to match '08' rather than '01' but boost matches nothing.


    With Dinkumware's tr1 implementation the match succeeds.

    > Even worse if I try and declare a regex that uses a lookbehind for e.g.
    > 'boost::regxCarFile( L"(?<=BAR)[0-9]{2}" )' I get bad_exception thrown
    > from boost.
    >


    That's "bad_expression", right? <g> That's because lookbehind isn't
    supported. But you don't need it here. This expression matches the first
    pair of digits: "([0-9]{2})_BAR".

    TR1's default regular expression grammar is ECMAScript, with
    modifications. ECMAScript doesn't do lookahead or lookbehind. You can
    also choose from several UNIX variants, but they don't to them, either.
    For details of the regular expression grammars that TR1's regular
    expressions support, see chapter 15 of my book, "The C++ Standard
    Library Extensions: a Tutorial and Reference."

    --

    -- Pete

    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." For more information about this book, see
    www.petebecker.com/tr1book.
     
    Pete Becker, Nov 9, 2006
    #2
    1. Advertising

  3. Guest

    You're right, it's an over-simplification (a habit of mine!) to
    illustrate the point. I just envisaged that lookarounds may be useful
    in the near future, until then I can use sub-expressions in parenthesis
    to capture to $1 (m[1]), $2 (m[2]), etc.

    Having recently migrated from VS6 to VS2005, I don't think our
    development teams processes can stand the hit of migrating to another
    STL platform at the moment, though I'm sure there are good arguments
    for and against. Would I be right in thinking that VS2005 is TR1 (more
    or less) out of the box, or not at all?

    I seem to recall seeing something about being able to call Perl from
    Cpp on the CPAN (or similar) site a while back, that may help me with
    lookarounds in the future. Then again, it may have been about calling
    Cpp from Perl which wouldn't be so good.

    Thanks,

    Duncan.


    On Nov 9, 12:39 pm, Pete Becker <> wrote:
    > wrote:
    > > Are lookarounds supported in the boost regex lib?I'm not up on the full details of boost's regex library, but TR1's regex

    > library is based on it, and it doesn't support lookahead or lookbehind.
    > There are no proposals to add them.
    >
    > > In my VS6 project
    > > using boost 1.32.0 I can declare a regex as..

    >
    > > <code_snippet>
    > > std::wstring wstrFilename = L"01_BAR08";

    >
    > > boost::wregex regxCarFile( L"(?=BAR)BAR[0-9]{2}" );
    > > bRet = boost::regex_search( wstrFilename, m, regxCarFile,The assert in this regular expression doesn't add anything.

    > L"BAR[0-9]{2}" says the same thing. Of course, it could be that this
    > example is oversimplified.
    >
    > > boost::match_default );
    > > if( true == bRet )
    > > {
    > > // No match! never gets here.
    > > }
    > > </code_snippet>

    >
    > > ..hoping to match '08' rather than '01' but boost matches nothing.With Dinkumware's tr1 implementation the match succeeds.

    >
    > > Even worse if I try and declare a regex that uses a lookbehind for e.g.
    > > 'boost::regxCarFile( L"(?<=BAR)[0-9]{2}" )' I get bad_exception thrown
    > > from boost.That's "bad_expression", right? <g> That's because lookbehind isn't

    > supported. But you don't need it here. This expression matches the first
    > pair of digits: "([0-9]{2})_BAR".
    >
    > TR1's default regular expression grammar is ECMAScript, with
    > modifications. ECMAScript doesn't do lookahead or lookbehind. You can
    > also choose from several UNIX variants, but they don't to them, either.
    > For details of the regular expression grammars that TR1's regular
    > expressions support, see chapter 15 of my book, "The C++ Standard
    > Library Extensions: a Tutorial and Reference."
    >
    > --
    >
    > -- Pete
    >
    > Author of "The Standard C++ Library Extensions: a Tutorial and
    > Reference." For more information about this book, seewww.petebecker.com/tr1book.
     
    , Nov 9, 2006
    #3
  4. Guest

    I've just been pointed to GRETA
    <<http://research.microsoft.com/projects/greta/>> - a regex lib by
    Microsoft. Claims to be fully Perl-5 compliant and I'm told it's fast
    in comparison to boost. My expectations are high!

    On Nov 9, 1:59 pm, wrote:
    > You're right, it's an over-simplification (a habit of mine!) to
    > illustrate the point. I just envisaged that lookarounds may be useful
    > in the near future, until then I can use sub-expressions in parenthesis
    > to capture to $1 (m[1]), $2 (m[2]), etc.
    >
    > Having recently migrated from VS6 to VS2005, I don't think our
    > development teams processes can stand the hit of migrating to another
    > STL platform at the moment, though I'm sure there are good arguments
    > for and against. Would I be right in thinking that VS2005 is TR1 (more
    > or less) out of the box, or not at all?
    >
    > I seem to recall seeing something about being able to call Perl from
    > Cpp on the CPAN (or similar) site a while back, that may help me with
    > lookarounds in the future. Then again, it may have been about calling
    > Cpp from Perl which wouldn't be so good.
    >
    > Thanks,
    >
    > Duncan.
    >
    > On Nov 9, 12:39 pm, Pete Becker <> wrote:
    >
    > > wrote:
    > > > Are lookarounds supported in the boost regex lib?I'm not up on the full details of boost's regex library, but TR1's regex

    > > library is based on it, and it doesn't support lookahead or lookbehind.
    > > There are no proposals to add them.

    >
    > > > In my VS6 project
    > > > using boost 1.32.0 I can declare a regex as..

    >
    > > > <code_snippet>
    > > > std::wstring wstrFilename = L"01_BAR08";

    >
    > > > boost::wregex regxCarFile( L"(?=BAR)BAR[0-9]{2}" );
    > > > bRet = boost::regex_search( wstrFilename, m, regxCarFile,The assert in this regular expression doesn't add anything.

    > > L"BAR[0-9]{2}" says the same thing. Of course, it could be that this
    > > example is oversimplified.

    >
    > > > boost::match_default );
    > > > if( true == bRet )
    > > > {
    > > > // No match! never gets here.
    > > > }
    > > > </code_snippet>

    >
    > > > ..hoping to match '08' rather than '01' but boost matches nothing.With Dinkumware's tr1 implementation the match succeeds.

    >
    > > > Even worse if I try and declare a regex that uses a lookbehind for e.g.
    > > > 'boost::regxCarFile( L"(?<=BAR)[0-9]{2}" )' I get bad_exception thrown
    > > > from boost.That's "bad_expression", right? <g> That's because lookbehind isn't

    > > supported. But you don't need it here. This expression matches the first
    > > pair of digits: "([0-9]{2})_BAR".

    >
    > > TR1's default regular expression grammar is ECMAScript, with
    > > modifications. ECMAScript doesn't do lookahead or lookbehind. You can
    > > also choose from several UNIX variants, but they don't to them, either.
    > > For details of the regular expression grammars that TR1's regular
    > > expressions support, see chapter 15 of my book, "The C++ Standard
    > > Library Extensions: a Tutorial and Reference."

    >
    > > --

    >
    > > -- Pete

    >
    > > Author of "The Standard C++ Library Extensions: a Tutorial and
    > > Reference." For more information about this book, seewww.petebecker.com/tr1book.
     
    , Nov 9, 2006
    #4
  5. Pete Becker Guest

    wrote:
    >
    > Having recently migrated from VS6 to VS2005, I don't think our
    > development teams processes can stand the hit of migrating to another
    > STL platform at the moment, though I'm sure there are good arguments
    > for and against. Would I be right in thinking that VS2005 is TR1 (more
    > or less) out of the box, or not at all?
    >


    VS2005 does not include TR1. The Boost libraries have quite a bit of
    what's in TR1, since much of TR1 came through Boost. But if you need a
    complete implementation, Dinkumware's the only game in town.

    --

    -- Pete

    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." For more information about this book, see
    www.petebecker.com/tr1book.
     
    Pete Becker, Nov 9, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Latter
    Replies:
    2
    Views:
    2,910
    Julie
    May 17, 2004
  2. Barry
    Replies:
    1
    Views:
    469
    Eric Niebler
    Jul 11, 2007
  3. ¿­ÖÐ
    Replies:
    4
    Views:
    499
    James Kanze
    May 11, 2008
  4. Gabriel Rossetti
    Replies:
    0
    Views:
    588
    Gabriel Rossetti
    Mar 31, 2009
  5. MRAB
    Replies:
    0
    Views:
    531
Loading...

Share This Page