473,804 Members | 3,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sz Expr);

bResult = boost::regex_ma tch(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 3710

"Richard Latter" <ri*******@latt er.demon.co.uk> wrote in message
news:c8******** ***********@new s.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(sz Expr);

bResult = boost::regex_ma tch(szSearch, *cExpr);

delete (cExpr);

return bResult;
}
Why are you allocating memory dynamically?

bool TestStr (std::string szExpr, std::string szSearch)
{
return boost::regex_ma tch(szSearch, boost::regex(sz Expr));
}

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_ma tch(szSearch, boost::regex(sz Expr));
}

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
3182
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 libraries. Here's my situation. My system is Red Hat Linux 9, using the Borland C++BuilderX Personal IDE (which uses the g++ compiler).
7
7807
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 << boost::regex_replace(string("foo"), boost::regex(".*"), string("bar")) << endl; The above code prints "barbar" where I expect "bar". Can anyone shed some light on this? It used to work with 1.30 (though regex_replace
5
5403
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 Windows platform? thanks in advance seth
5
7193
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 // Boost.Regex lib using namespace std;
4
4404
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 regxCarFile( L"(?=BAR)BAR{2}" ); bRet = boost::regex_search( wstrFilename, m, regxCarFile, boost::match_default ); if( true == bRet )
1
4463
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 <iterator> #include <boost/regex.hpp>
3
2812
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 everything between and replace with <pre>, with </pre>. Meanwhile, everything outside should be unchaged except that < is
2
1497
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 able to use both the boost regex library and the language regex features? Or would boost community abandon regex? 2) would boost still exist as a library? Or its entire purpose is to serve as the tr1 playground? Many thanks, cheers, kev
13
4536
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. Any tips? #include <boost/regex.hpp> #include <iostream> // g++ numbers.cpp -o numbers -I/usr/local/include/boost-1_35 /usr/local/lib/libboost_regex-gcc41-mt-s.a // g++ numbers.cpp -o numbers.exe
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.