By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,106 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,106 IT Pros & Developers. It's quick & easy.

Does boost's regex lib support the lookbehind feature?

P: n/a
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 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
DS********@googlemail.com 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? <gThat'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.
Nov 9 '06 #2

P: n/a
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 <petebec...@acm.orgwrote:
DSmith1...@googlemail.com 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? <gThat'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 '06 #3

P: n/a
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, DSmith1...@googlemail.com 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 <petebec...@acm.orgwrote:
DSmith1...@googlemail.com 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? <gThat'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 '06 #4

P: n/a
DS********@googlemail.com 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.
Nov 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.