Hi, My problem is really simple : I have several regular expressions (like (19[4-9]\d)|(200\d)|( [09]\d ) ) which work when they correspond to the entire string, e.g. : "2002" OK; "something 2002 something" NOT OK. Everythings worked fine with the GRETA library, and now, it doesn't. Does anyone have an idea ? Thanks. Fred
I haven't used GRETA but if you are asking about Boost Regex++, posting some
code would help and defining what you mean by not working would also help.
There are different Regex++ string search functions and the regex_match has
to match the entire input sequence to return true. Is it possible that is
what you are using ?
"Frédéric Mayot"
Hi,
My problem is really simple : I have several regular expressions (like (19[4-9]\d)|(200\d)|( [09]\d ) ) which work when they correspond to the entire string, e.g. : "2002" OK; "something 2002 something" NOT OK.
Everythings worked fine with the GRETA library, and now, it doesn't.
Does anyone have an idea ?
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); }
"Frédéric Mayot"
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); }
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".
Use regex_search, supplying a -1 index to the match_results class will give you what perl calls $` and supplying a -2 index gixes you what perl calls $' (which is what you want in this case).
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 ?
I don't know much about CString, but it looks like: boost::cmatch what; if(regex_search(...args)) { CString s(what[0].first, what.length()); } will do what you want. John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
My problem is really simple : I have several regular expressions (like (19[4-9]\d)|(200\d)|( [09]\d ) ) which work when they correspond to the entire string, e.g. : "2002" OK; "something 2002 something" NOT OK.
Everythings worked fine with the GRETA library, and now, it doesn't.
Does anyone have an idea ?
My suspicion is that you are using regex_match when you meant to use regex_search. John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
participants (3)
-
Edward Diener
-
Fr�d�ric Mayot
-
John Maddock