|
Boost Users : |
From: Edward Diener (eddielee_at_[hidden])
Date: 2002-08-23 17:31:59
"Frédéric Mayot" <yg-boost-users_at_[hidden]> wrote in message
news:ak4sh0$1s7$1_at_main.gmane.org...
> OK, I didn't read the documentation carrefully... (sorry)
> But I still don't understand how to do what I want with boost regex.
>
> It's simple : I have a string and a regular expression. I only want to
find
> the FIRST sub-string which matches my regular expression (S), then to
> extract the sub-string before S and the sub-string after S.
>
> An example :
> my string : "2001 2002 something"
> my regexp : 200\d
>
> Nevermind what regex matches first (either 2001, or 2002). Let's suppose
it
> matches "2002".
> I want to create three strings "2001 ", "2002" and finally " something".
You can use regex_search. Your match_results will tell you both the string
after the match and before the match as well as what matched and what each
sub-expression matched.
>
> That's all, except that I need to do that as QUICK as possible (that's why
> I'm testing another library).
I understand that the Boost author of Regex++, Dr. John Maddock, is working
on means to speed up Regex++ greatly for future releases, but you will have
to wait for that.
>
> I have another pb. I'm using MFC and CString objects. I didn't see a way
of
> catching the substrings without using a temporary std::string object (it's
> not very efficient because it creates a std::string object, then I need to
> call a cast operator to get a char*, then it creates my CString object
from
> the char*...)
I have a free implementation of Regular Expressions based on Dr. John
Maddock's pre-Boost version of Regex++ which supports VC6, MFC, and CString
at http://www.tropicsoft.com/Components/RegularExpression . You might want
to look into that if you find the Boost version too daunting to use. My next
version, based on Boost Regex++,will be out shortly. I mention that only
because you seem to need a version that integrates more easily with VC and
MFC and not to promote my own library over Boost's version, since it
essentially uses the Boost version internally.
>
> Can you give me some clues ?
>
> Thanks a lot.
>
> Fred
>
>
****************************************************************************
> ***
> MY CODE (which works fine when the entire string sText is matched) :
> ------------------
> oRegExp->RegExp = new boost::regex((LPCSTR) sRegExp);
> ------------------
>
> if (regex_match((LPCSTR) sText, oResults, *oRegExp->RegExp))
> {
> if (oResults[-1].length() > 0)
> temp = std::string(oResults[-1].first, oResults[-1].second);
>
> temp = std::string(oResults[0].first, oResults[0].second);
>
> if (oResults[-2].length() > 0)
> temp = std::string(oResults[-2].first, oResults[-2].second);
> }
>
>
>
>
>
>
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net