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

Any Boost Experts out there for Boost.Regex?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.