Does boost's regex lib support the lookbehind feature?

D

DSmith1974

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.
 
P

Pete Becker

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.
 
D

DSmith1974

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.


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.
 
D

DSmith1974

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!

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.

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.
 
P

Pete Becker

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top