473,320 Members | 1,744 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,320 software developers and data experts.

Any Boost Experts out there for Boost.Regex?

Hello All,

I am a newbie to the Boost library and I have a question about a simple
function. All I would like to do is to create a simple function that can
test strings using regular expressions. I've written this function which
appears to work on the first pass and then fails on the second with the
following message.

Unhandle exeption in Credit Card Example.exe (KERNEL32.DLL) 0x(Some
address): Microsoft C++ Exception.

My function is as follows....

bool TestStr (std::string szExpr, std::string szSearch)
{
bool bResult=false;

boost::regex *cExpr = new boost::regex(szExpr);

bResult = boost::regex_match(szSearch, *cExpr);

delete (cExpr);

return bResult;
}

Questions!

1. Why is this failing all the time?

2. Why in the example given in the RTL is a constant? This implies that
the the regex object cannot be changed at run-time, which is the opposite to
what I would like to do.

3. Are there any examples or tutorials outside of the main library tutorial
I could look at? Are there any newsgroups on this?

4. Can anyone give an example of a simple POSIX calls for string matching?

Please forgive me as I'm a newbie to all of this. Any help would be
gratefully appreciated.

Regards,

Richard
Jul 22 '05 #1
2 3682

"Richard Latter" <ri*******@latter.demon.co.uk> wrote in message
news:c8*******************@news.demon.co.uk...
Hello All,

I am a newbie to the Boost library and I have a question about a simple
function. All I would like to do is to create a simple function that can
test strings using regular expressions. I've written this function which
appears to work on the first pass and then fails on the second with the
following message.

Unhandle exeption in Credit Card Example.exe (KERNEL32.DLL) 0x(Some
address): Microsoft C++ Exception.

My function is as follows....

bool TestStr (std::string szExpr, std::string szSearch)
{
bool bResult=false;

boost::regex *cExpr = new boost::regex(szExpr);

bResult = boost::regex_match(szSearch, *cExpr);

delete (cExpr);

return bResult;
}
Why are you allocating memory dynamically?

bool TestStr (std::string szExpr, std::string szSearch)
{
return boost::regex_match(szSearch, boost::regex(szExpr));
}

The above is simpler and likely to be more efficient. Also you should use
const references for your strings

bool TestStr (const std::string& szExpr, const std::string& szSearch)
{
return boost::regex_match(szSearch, boost::regex(szExpr));
}

Again this is a likely efficiency gain at no cost.

Questions!

1. Why is this failing all the time?

Who knows? It could be a bug in your code, it could be a bug in
boost::regex, it could be a bug in your compiler, it could be a bug in your
implementation of the standard library. One thing is sure just because it
fails on the second pass though boost does not mean that the bug is in the
boost library. The best thing is to post a complete compilable program that
shows the crash. Then people will be able to try it with their compilers and
at least eliminate some of the possibilities.

2. Why in the example given in the RTL is a constant? This implies that
the the regex object cannot be changed at run-time, which is the opposite to what I would like to do.


I don't think it implies that at all. It imples that in that piece of code
the author did not want to change the regex object.

john
Jul 22 '05 #2
Richard Latter wrote:
[snip boost-related stuff]

Your question would be more topical and you would probably get better answers
on the Boost newsgroup:

news://news.gmane.org/gmane.comp.lib.boost.devel
Jul 22 '05 #3

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...
7
by: derek.google | last post by:
I hope a Boost question is not too off-topic here. It seems that upgrading to Boost 1.33 broke some old regex code that used to work. I have reduced the problem to this simple example: cout <<...
5
by: Seth | last post by:
I can't get this thing made for the life of me. I've gone through every step per the Boost website regarding using bjam. Nothing. Can anyone give any advice or are there pre-made boost hpps for...
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 //...
4
by: DSmith1974 | last post by:
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...
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...
3
by: MCH | last post by:
hi there, I am working with a HTML-like text with boost:regex. For example, the following pattern might occur in my text <abc efg> <p>EFG</p 12<3> In this case, I would like to extract...
2
by: kvnil | last post by:
Could someone please explain what will happen with boost (and tr1) once c++09 is out. Take regex for example. There would (probably) be a regex support in c++09. 1) Does that mean I would be...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.