Boost logo

Boost Users :

From: Frédéric Mayot (yg-boost-users_at_[hidden])
Date: 2002-08-23 03:39:56


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".

That's all, except that I need to do that as QUICK as possible (that's why
I'm testing another library).

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*...)

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