473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Does boost's regex lib support the lookbehind feature?

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
4 4373
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: sbobrows | last post by:
{Whilst I think much of this is OT for this newsgroup, I think the issue of understanding diagnostics just about gets under the door. -mod} Hi, I'm a C++ newbie trying to use the Boost regex...
4
by: Hardy Wang | last post by:
Hi: I have a XML like <?xml version="1.0" ?> <object> <comments>www.site.com/page.aspx?param1=value1&param2=value2</comments> </object> Since "&" is invalid in XML, I need to replace all "&"...
0
by: Andrew Ayre | last post by:
Hi, I can't seem to get the library built, and any help is greatly appreciated. Here is the info: Windows XP Borland C++ Builder 5 Latest Boost source code (downloaded at the weekend) Windows...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
5
by: FBergemann | last post by:
I use SunOS 5.8, gcc 3.3.2, boost 1.33.1. I have build the entire boost package and try to compile a simple example: #include <iostream> #include <string> #include <boost/regex.hpp //...
1
by: Yahooooooooo | last post by:
Just practicing BOOST regular expressions....giving errors... -- wanted to replace SPACE with NULL. #include <iostream> #include <fstream> #include <sstream> #include <string> #include...
0
by: marcell71 | last post by:
I'm trying to get Boost.Python to working using the instructions here: http://www.boost.org/libs/python/doc/building.html. I am on step 3.1.4 and am getting a linking error that I can't figure out....
4
by: =?GB2312?B?v63W0A==?= | last post by:
#include <iostream> #include <string> #include <boost/regex.hpp> using namespace std; int main(int argc, char* argv) { string inStr = "123456" "abcde"
13
by: brad | last post by:
Still learning C++. I'm writing some regex using boost. It works great. Only thing is... this code seems slow to me compared to equivelent Perl and Python. I'm sure I'm doing something incorrect....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.