|
|
Comments and Discussions
|
|
 |

|
My environment is Visual Studio 6, WinXP Pro
Why would this fail?
const char *pattern = "*.txt";
RegEx e(pattern, TRUE);
bMatched = e.Match("test.txt");
The RegEx constructor fails, returning a REG_BADRPT code.
This one doesn't throw an exception, but doesn't match, either:
const char *pattern = "tes?.txt";
RegEx e(pattern, TRUE);
bMatched = e.Match("test.txt");
This succeeds, and matches as expected...
const char *pattern = "test.txt";
RegEx e(pattern, TRUE);
bMatched = e.Match("test.txt");
This seems like a trivial case, yet I can't make it work... what am I missing?
|
|
|
|

|
"*.txt" is invalid regex. The asterisk (*) will match zero or more of the character before it, and since there are no characters before it, that is not a valid match. Also a period (.) matches any single character except for null's and newlines. So that is not a valid regex. "tes?.txt" is valid regex. A question mark (?) matches the character before it zero or one times. And since it also has a period, which matches any single character except null's and newlines, it will match something like "te4txt" and "tesvtxt" and so forth, but it will certainly not match "test.txt". "test.txt" is valid regex. All the characters will match themselves, except for period (.), which will match anything except null's and newlines, meaning it does match periods. So it will match "test.txt", but it will also match things like "testytxt" and "testqtxt" and so forth as well. The problem seems to be that you are using wildcard matching, not regex matching. These are two different, incompatible matching schemes. Regex is vastly more powerful then wildcard matching, and considering this is an article for a regex parser, and not a wildcard parser, it makes sense that wildcard matching would not work. Instead of the wildcard "*.txt", you probably want the regex ".*\.txt", the "\." is an escaped period, meaning match the period itself, just like how \"'s means put a double quotation mark in a string instead of ending the string in most programming languages. Instead of the wildcard "tes?.txt", you probably want the regex "tes.\.txt". Instead of the wildcard "test.txt", you probably want the regex "test\.txt". Also, in ones like ".*\.txt", if you want to enforce that there is at least one character, you can use a plus (+) instead of an asterisks (*) as a plus means one or more, where-as the asterisks means zero or more, so doing ".+\.txt" would mean to match a string with at least one, but infinitely many characters, then ending in a ".txt". Regex also has the capability to match a length of a match of characters as well, so you could restrict the count of the starting characters to be a minimum of 1 and a maximum of 8 so you could have an old DOS style 8.3 filename matching with your files ending in ".txt".
|
|
|
|

|
I am getting the following error when I try to compile in VxWorks environment. :
bash.exe: warning: could not find /tmp, please create!
In file included from ../boost/config.hpp:40,
from ./../libs/regex/src/c_regex_traits.cpp:25:
../boost/config/select_stdlib_config.hpp:18: utility: No such file or directory
In file included from ../boost/config.hpp:53,
from ./../libs/regex/src/c_regex_traits.cpp:25:
../boost/config/platform/cygwin.hpp:21: unistd.h: No such file or directory
In file included from ../boost/config/platform/cygwin.hpp:36,
from ../boost/config.hpp:53,
from ./../libs/regex/src/c_regex_traits.cpp:25:
../boost/config/posix_features.hpp:17: unistd.h: No such file or directory
In file included from ../boost/config.hpp:57,
from ./../libs/regex/src/c_regex_traits.cpp:25:
../boost/config/suffix.hpp:26: limits.h: No such file or directory
./../libs/regex/src/c_regex_traits.cpp:31: clocale: No such file or directory
./../libs/regex/src/c_regex_traits.cpp:32: cstdio: No such file or directory
./../libs/regex/src/c_regex_traits.cpp:33: list: No such file or directory
./../libs/regex/src/c_regex_traits.cpp:34: cctype: No such file or directory
./../libs/regex/src/c_regex_traits.cpp:35: cstdio: No such file or directory
In file included from ../boost/regex/v3/cregex.hpp:28,
from ../boost/cregex.hpp:27,
from ./../libs/regex/src/c_regex_traits.cpp:36:
../boost/regex/config.hpp:84: cstdlib: No such file or directory
../boost/regex/config.hpp:85: cstddef: No such file or directory
../boost/regex/config.hpp:86: cstring: No such file or directory
../boost/regex/config.hpp:87: cctype: No such file or directory
../boost/regex/config.hpp:88: cstdio: No such file or directory
../boost/regex/config.hpp:89: clocale: No such file or directory
../boost/regex/config.hpp:90: cassert: No such file or directory
../boost/regex/config.hpp:91: string: No such file or directory
../boost/regex/config.hpp:92: stdexcept: No such file or directory
../boost/regex/config.hpp:93: iterator: No such file or directory
In file included from ../boost/regex/config.hpp:95,
from ../boost/regex/v3/cregex.hpp:28,
from ../boost/cregex.hpp:27,
from ./../libs/regex/src/c_regex_traits.cpp:36:
../boost/cstdint.hpp:134: limits.h: No such file or directory
../boost/cstdint.hpp:158: #error defaults not correct; you must hand modify boos
t/cstdint.hpp
../boost/cstdint.hpp:188: #error defaults not correct; you must hand modify boos
t/cstdint.hpp
../boost/cstdint.hpp:208: #error defaults not correct; you must hand modify boos
t/cstdint.hpp
../boost/cstdint.hpp:236: warning: integer constant is so large that it is unsig
ned
../boost/cstdint.hpp:246: #error defaults not correct; you must hand modify boos
t/cstdint.hpp
In file included from ../boost/regex/config.hpp:96,
from ../boost/regex/v3/cregex.hpp:28,
from ../boost/cregex.hpp:27,
from ./../libs/regex/src/c_regex_traits.cpp:36:
../boost/detail/allocator.hpp:20: cstdlib: No such file or directory
../boost/detail/allocator.hpp:61: memory: No such file or directory
In file included from ../boost/cregex.hpp:27,
from ./../libs/regex/src/c_regex_traits.cpp:36:
../boost/regex/v3/cregex.hpp:203: string: No such file or directory
../boost/regex/v3/cregex.hpp:204: vector: No such file or directory
In file included from ../boost/regex/v3/regex_traits.hpp:30,
from ../boost/regex/regex_traits.hpp:27,
from ./../libs/regex/src/c_regex_traits.cpp:37:
../boost/regex/v3/regex_cstring.hpp:32: cstring: No such file or directory
In file included from ../boost/regex/regex_traits.hpp:27,
from ./../libs/regex/src/c_regex_traits.cpp:37:
../boost/regex/v3/regex_traits.hpp:547: locale: No such file or directory
In file included from ./../libs/regex/src/c_regex_traits.cpp:38:
../boost/regex/v3/regex_synch.hpp:34: windows.h: No such file or directory
In file included from ../boost/scoped_array.hpp:15,
from ./../libs/regex/src/c_regex_traits.cpp:40:
../boost/assert.hpp:36: assert.h: No such file or directory
In file included from ./../libs/regex/src/c_regex_traits.cpp:40:
../boost/scoped_array.hpp:18: cstddef: No such file or directory
make[3]: *** [obj/96xx/release/./../libs/regex/src/c_regex_traits.o] Error 1
make[2]: *** [libregex.lib] Error 2
make[1]: *** [regex.lib] Error 2
make: *** [regex] Error 2
Build Results
-------------
Start: 19:58:07 July 30, 2007
End: 19:58:09 July 30, 2007
Elapsed: 00:00:02
Errors: 4
Warnings: 14
Can anyone help me with this ??... Are few files missing from the code as the errors indicate that some file or directory cannot be found.
|
|
|
|

|
Would anyone know how to use this library to replace 'grepped' matches in a string with another string?
Thanks for your help!
Mike
|
|
|
|

|
In C++ .NET it looks like:
newString = Regex::Replace(oldString,pattern,replacementString);
Visit our site Emergency Soft
|
|
|
|

|
Just built the regex++ v3 library, no problems there.
Hooked into into my project, no problems....but....
When I come to compile I have a raft of C2668 "ambiguous call to overloaded function" errors.
I know i must be overlooking something simple but I can think what. I've tried using namespace std; when needed, but the only fix so far has been to scope the calls std::memcpy() std::strlen etc..
However I'm getting the error for the vc98\mfc\include\xxxx.h files which I don't want to meddle with.
Does anyone have any suggestions? perhaps i've missed something obvious.
Thanks in advance,
Chris.
example of the errors:
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(373) : error C2668: 'memcpy' : ambiguous call to overloaded function
c:\program files\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'void __thiscall CArray::SetSize(int,int)'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(373) : error C2668: 'memcpy' : ambiguous call to overloaded function
c:\program files\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'void __thiscall CArray::SetSize(int,int)'
cdlghelp.cpp
|
|
|
|

|
Thats bizarre ! I've used that version of regex++ for a long time with MSVC 6 SP5 and Ive never seen it do that.
I did a test with a minimal console program with MFC support (looking at the afx... includes), and still I didnt get the issue ....
what sequence of includes do you have around the line :-
#include <boost/regex.hpp>
? and have you tried moving the regex.hpp include around ? (I usually keep it close to the last include, after all windows, stl etc)
sorry, not likely much help
'g'
|
|
|
|

|
Yeah has got me stumped... kinda..
I've got the include as below taken from one of the Boost examples.
#include
#include "boost/regex.hpp"
using namespace std;
using namespace boost;
I've fixed the problem at the moment by scoping all the suspect calls in my code, simply using ::memcpy() ::strlen() etc. But I've had to tweak slightly some of the VC98 headers to fix them.
Not ideal, but I need to plod on for now. Having done some digging it seems that having "using namespace std;" anywhere in my code can be the cause of this error, but have no idea how to resolve it as it is used all over the place.
I dug around in config.hpp and there seems to be some #defines related to the problem but i've experimented with them with no joy so far.
I might be forced to try an alternative Regular Expression library if I can resolve this satisfactorily which would be a bit of a shame.
|
|
|
|

|
how to extract the phoneno using regex in all countries
dwddx
|
|
|
|

|
Hi
I am using following statement for pattern matching
std::string strPattern = "^*?\\s(from)[\\s]{1,}$*";
boost::regex(strPattern);
it is failing at the second statement.
Could you help me fixing out this problem.
Thanks
john
|
|
|
|

|
" Note: To add the Regex++ library to your project select Project | Settings.... In the ensuing dialog, select the C/C++ tab. In the Category drop down list, select Preprocessor. In the Additional include directories: edit box enter C:\Regex++. Now select the Link tab. In the Category drop down list, select Input. In the Additional library path: edit box enter C:\Regex++."
How to do this in Visual C++ 7 ?
|
|
|
|

|
The tabs are different but the settings are pretty much the same. The idea is that you have to specify the include directory where the regex header files are located, and then you have to specify where the static libraries are so that the compiler can link those in.
If you are confused about project settings in visual studio, then I would suggest that you probably need to gain a better understanding of that first before trying to build this project. When the article was written, Visual Studio was still in version 6.0. I have not updated this article and don't have plans to any time soon so I'm afraid you're on your own to figure it out for the version of visual studio you're using.
Best Regards,
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Hello;
sorry for my bad english.
How can I change the example above, that work with Unicode version.
I don't know if it's a good splution but I try for example to change :
std::string str = _T("hello word, hello every body, hello friend");
boost::RegEx expr("hello[^,]",TRUE);
std::vector v;
expr.Grep(v, str );
TO:
std::wstring wstr = _T("hello word, hello everybody, hello friend");
boost::wregex expr("hello",TRUE);
std::vector v;
expr.grep(v, wstr);
I've got the next message error from VC++ 6 under XP:
error C2064: term does not evaluate to a function
Can you help me please ?
Thanks;
-- modified at 18:39 Tuesday 25th April, 2006
|
|
|
|

|
Does Regex++ support UNICODE, wstring and TCHAR?
I can seem to find a way to get it work with UNICODE. Any clues?
thanks.
Sonork 100.41263:Anthony_Yio
|
|
|
|

|
From the boost website: ..."the library provides full Unicode support under NT, under Windows 9x the library degrades gracefully - characters 0 to 255 are supported, the remainder are treated as "unknown" graphic characters."
You can read more here: http://www.boost.org/libs/regex/doc/localisation.html[^]
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Hi,
Thank you providing this article , it is very useful.
I am using regEx for searching any string in a given file ( Eg:- strings like "hello" ). I tried using the regular expression \{"[^"]*"\!'[^']*'\}, but it is not returning any match !
Can someone point out what i am doing wrong , or please provide a regular expression which i can use to search for strings.
Thanks in advance
regards
Ratheesh
|
|
|
|

|
The most helpful suggestion I have is to get Jeffrey Friedl's book Mastering Regular Expressions and read it until you understand how to use regular expressions effectively.
I can't really help you find the word hello because the regular expression to find the word hello is hello. If you can clarify, I can try to help.
One other resource I can suggest is the Regular Expression tutorial recently listed on this site at: http://www.codeproject.com/useritems/RegexTutorial.asp[^] . It is geared towards Regex on .NET, but the principles are the same and the syntax is very similar.
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Hi,
Thank u for replying .
I will make my self clear . I am trying to find strings in a file .
for this i was trying to use the regular exp \{"[^"]*"\!'[^']*'\} but it is not returning anything.
regards
Ratheesh
|
|
|
|

|
That is the same thing you said in your first post. It doesn't make any more sense the second time around. I can see at least one problem with your regex, though, so I will try to help with that.
You seem to by trying to escape the exclamation mark which doesn't make any sense. Exclamation marks are not special characters. Here is how I would interpret your regex ignoring the escape you have on your exclamation mark as follows:
Find an opening curly brace followed by a quotation mark followed by zero or more characters that are anything except a quotation mark followed by a quotation mark followed by an exclamation ponit followed by a single quote followed by zero or more characters that are anything except a single quote followed by a single quote followed by a closing curly brace.
The actual regex should look like this \{"[^"]*"![[^']*'\}
This regex would match something like this:
{"Bob was here"!'And so was Marge'}
However it will also match this:
{""!''}
If you want to ensure it matches something inside your quotation marks and single quotes, change the * (match zero or more) with + (match one or more).
Hope that helps. Let me know if you have further questions.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
I think what the original poster wanted was something along the lines of ("[^"]")|('[^']'), that will search for strings enclosed by quotation marks of single quotes. He must have mistook the '!' for the '|'.
|
|
|
|

|
I'm trying to use the Regexp library inside a VC6 project that uses another library too. But, I'm getting the following compiler error when I try to include :
c:\program files\microsoft visual studio\vc98\include\new(35) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\include\new(35) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\include\new(35) : error C2809: 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\include\new(36) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio\vc98\include\new(37) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\include\new(37) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl op
erator new(void))(unsigned int)'
c:\program files\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
d:\work\regexp\boost\detail\allocator.hpp(279) : fatal error C1506: unrecoverable block scoping error
Can you help me, please?
|
|
|
|

|
I think it's trying to link against the wrong library or something. Make sure that your STL includes preceed your MFC includes. If that doesn't work, then do a search on google and paste in your error messages. I find this to be an effective way to find discussions on specific errors.
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Hello perlmunger,
I have just downloaded the regex++ from the link you pointed out in this article. However, after some checking, I found that Dr Maddock does not update the library as regular as to compare with the version in Boost.
I had compared the number of makefiles avail for regex++ in boost 1.31 with the one in the regex++ author's web page. It seems that the newer version of regex++ comes with an additional makefile named vc71.mak for VC7.1 users.
So, I guess the proper place to download regex++ would be from the boost web site instead?
Sonork 100.41263:Anthony_Yio
|
|
|
|

|
It hasn't been my top priority to update this article, though I intend to. I think you are right and I will change the link once I do get a chance.
Thank you.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
BTW, thank you for your great article.
Sonork 100.41263:Anthony_Yio
|
|
|
|

|
Looks like this doesn't work with VC7.1. I was able to build the library, but I get nothing but link errors. The instructions are silly because they say you don't need to specify any lib folder or include any lib files in your project, but that obviously is not the case.
|
|
|
|

|
Try to use the regex++ in the boost library instead. The one in Maddock web site was not up to date. (the time when I check it) Rebuild the lib with the makefile specifically for VC7.1. It works for me.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|

|
The two links to www.boost.org (right above the GetActualType paragraph) do not work.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|

|
How can I statically link to the library, I dont think that everyone will have the dll on their machine.
As right now, I am working on a MFC dialog based application.
If I build using the setup as on the site, I can build fine and things work on my machine, but as soon as I go on another machine it starts asking for the dlls.
If I select to link Statically to the MFC then it works fine however,not if I select to link to MFC as a shared libarary.
Thanks again for all your help
|
|
|
|

|
Hi, I am a C++ beginner and failed to work out the sample of this acticle.
I am using Visual C++ 7 and installed boost as stated in the acticle.
When i try to complie and run the project, an error msg appear as follow:
"
RegexTest.exe - Unable To Locate Component
This application has failed to start because boost_regex_vc7_mdid.dll was not found. Re-installing the application may fix this problem."
It seems to me that the source is complied successfully but failed to find the "boost_regex_vc7_mdid.dll" in runtime...I am not sure but it may be the path settings problem.
Does anyone have any suggestion or solution to my problems?
|
|
|
|

|
I apologize for the inconvenience, however, this article (and subsequent project) has not been updated to work with Visual C++ 7 yet. I am trying to find the time to do just that, but am terribly busy lately.
If you feel so inclined, you can follow the buid instructions that come with boost::regex to build the missing dll that is mentioned in your error message. There is a separate make file in the boost distribution build directory just for this purpose. In all likelihood (if you followed the instructions in *this* article), you only built the boost_regex_vc6 dll and not the vc7 dll.
Thanks and good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
if you want to get this dll please write your EMail.
i will send to you this dll or send Email to me:arna4458@yahoo.com
-- modified at 12:36 Wednesday 27th December, 2006
|
|
|
|

|
Hi, I am pretty confused by the string types yet. How can I print a LPCTSTR variable in c++, I mean to print it out readable? For example, LPCTSTR mystr = (LPCTSTR).....; Can I use cout or printf to print it? cout<<mystr<<endl; or printf("%s\n", mystr);
Thanks, Peter
|
|
|
|

|
I don't see why not. Have you tried?
Frankly, I don't normally respond to anonymous posters because if you don't care to take the time to log in and indicate who you are, you probably are just shooting off a question without caring who's time you waste.
Just this once, however, I will try it out and see if you actually check back and see my answer.
A LPCTSTR is simply a const TCHAR*. A TCHAR is simply an MFC alias for char. However, if your code has the unicode pre-processor flag set, MFC TCHARs become wide-chars which are unsigned shorts.
I hope you're not asking a question about something that could have been easily tested.
-Matt
p.s. A simple google search yielded many links with answers to this question. The first thing any serious programmer should learn is to investigate the answer to a question before asking it. Of course we all get hasty from time to time, but I'm not even sure you considered finding it on your own.
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
First of all, thank you for this article. I have been trying to incorporate regex++ in my app, and in testing it I accidentally entered a bad regular expression, which caused an assert. So I am trying now to add exception handling. Please take a look at this and tell me if I am on right track:
try
{
boost::RegEx expr(m_strRegexp, FALSE);
expr.Grep(v, stdstr);
}
catch (const boost::bad_expression& be)
{
m_List.AddString(_T("ERROR: bad_expression"));
const char *buf = be.what();
m_List.AddString(buf);
MessageBeep((UINT)-1);
}
catch (const std::exception& e)
{
m_List.AddString(_T("ERROR: std exception"));
const char *buf = e.what();
m_List.AddString(buf);
MessageBeep((UINT)-1);
}
catch (...)
{
m_List.AddString(_T("ERROR: unknown exception"));
}
|
|
|
|

|
First you need to understand the difference between an assertion and an excetpion. They are different. Assertions are used to ensure that a particular statement is true or false (must happen or the program fails). They are generally only useful for programmers while building their applications. An exception, on the other hand, is used to handle a problem that may happen, but can be anticipated and dealt with when the application is production code. Your excetpion handling looks fine to me. If your program caused an assertion, however (as you stated in your question), then you are not going to be able to fix the problem with exceptions. You have to find the line of code where the assertion failed using the debugger and find out which statement failed to fulfill the requirements of the assertion. Usually when an assertion fails, there's a problem with the code.
Hope that helps. Let me know if you need more clarification or have further questions.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Thanks for the quick reply. I probably should not have called it an assertion. The error was reported by the "Microsoft Visual C++ Runtime Library" and the text of the error said that the runtime was terminated abnormally. Again, this was due to a badly formed re. For an example, try "ab(", and this is the error you will get. Fortunately, the try...catch handler catches it.
Best wishes,
Hans
|
|
|
|

|
Website seems to say it supports wide characters, but I can't find any examples or documentation that uses wide characters.
|
|
|
|
|

|
It would help if you would show me some code. But the regex you need to extract the text out is this "<::\s+([^\s]+)\s+::>" .
So if your RegEx variable was named "exp", the value you want is now in exp[1] because of the capturing parentheses.
Here's some code:
std::vector<std::string> capturedStrings;
for( int i = 0; i < v.size(); ++i )
{
std::string line = (std::string)v[i];
RegEx exp( "<::\\s+([^\\s]+)\\s+::>", TRUE );
if( exp.Search(line) )
{
capturedStrings.push( exp[1] );
}
}
Just to clarify, what the regex means is this: "look for <:: followed by one or more whitspace characters, then capture anything that is not whitspace and then look for one or more whitespace characters again and then look for ::>".
Does that help/make sense?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Here is my code
CStdioFile myfile,newFile;
CString inString = "";
char* fString="";
//char *pattern="((\\s*lmp\\s*))";
char *pattern="\\s*(LMP\\([0-9]+\\)).*)\\n";
//***********The line below when reached //causes abnormal termination,dont know /whats the problem Please help
RegEx exp(pattern,TRUE);
std::string wholeFileStr="";
CString wholeFileString = "",filname="c:\\test23.txt",nName="c:\\MunnaMunna.txt";
// Read entire file into a string.
try{
myfile.Open(filname,CFile::modeRead | CFile::typeText, NULL);
newFile.Open(nName,CFile::modeWrite , NULL);
}
catch (CFileException e)
{
MessageBox("The file " + filname + " could not be opened for reading", "File Open Failed", MB_ICONHAND|MB_ICONSTOP|MB_ICONERROR );
//return FALSE;
//myfile.Close();
//newFile.Close();
}
try{
while (myfile.ReadString(inString))
{//newFile.WriteString(inString);
//wholeFileString += inString;
wholeFileStr = inString.GetBuffer(2);
//
//const char *wholeFileStr=(LPCTSTR)inString;//.GetBuffer(10);
// RegEx exp("(\\*sLMP((0-9)+\)).*)\n$",TRUE);
// RegEx exp("(\s*LMP\([0-9]+\))",TRUE);
// RegEx exp("\s*LMP",TRUE);
if(exp.Search(wholeFileStr))
{
//strcpy(fString,exp[1].c_str());
CString sd(exp[1].c_str());
AfxMessageBox(sd);
}
else if(fString!="")
{ CString temp(fString);
//CString temp2(wholeFileStr);
temp+=inString;
temp+="\n";
//strcat(fString,wholeFileStr);
//strcat(fString,"\n");
newFile.WriteString(temp);
}
}
//***************************************************************
}
catch (CFileException e)
{
MessageBox("The file " + filname + " could not be opened for reading", "File Open Failed", MB_ICONHAND|MB_ICONSTOP|MB_ICONERROR );
//return FALSE;
//myfile.Close();
//newFile.Close();
}
newFile.Close();
myfile.Close();
|
|
|
|

|
Unfortunately, this problem could be any number of things. My gut feeling is that there is something wrong with your Regex++ build/install. What version of visual studio are you using? Did you do the Regex++ build for that version? (there are two make files--one for VC6 and one for VC7).
Beyond that, you're just going to have to debug it and see if you possiblly have code failing somewhere else.
I'm sorry I don't have a clearer answer for you.
Good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
I know now the problem is in the expression that I was building.
in perl i was using the following code
~m/^lmp\([0-9]+\).*)\n$/i
to get all lines which had lmp() in them where there are some digits between the parenthesis.
The problem is I am not being able to get the expression right and as have to complete the aplication in MFC/C++
there is no better alternative to regex++....am in a fix
Help!
|
|
|
|

|
Tell me exactly what you want your expression to do. Here is the way I read your current expression:
You are trying to find:
lmp( at the begging the line
followed by 1 or more digits
followed by )
followed by zero or more of any character
followed by a newline character
followed by the end of the line
The search is case insensitive.
Does this sound correct? In what you've provided though, there is a syntax error--or so it appears to me. You have a closing paren, but no opening paren. Is this just a typo for your message here, or is this in your original code? Here's what I mean. You have:
~m/^lmp\([0-9]+\).*)\n$/i
Notice that you have mismatched parens. The close paren after the .* has no corresponding open paren. I am assuming you are using these parens to capture something in $1 (in perl). It won't work unless you get the open paren in there. Let me know if I'm misinterpreting your regex.
Another thing that is curious to me is that you are looking for a \n as well as a $ which is the end of the line character. I don't think I've ever seen them used together before. That's not to say it's invalid, I've just never used it. The $ alone should give you what you're after.
If you can just give me an example line and what you want to extract out of it, I could help you with a more specific example. Let me know.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
I am using the following expression
exp.SetExpression("^(lmp\\([0-9]+\\).*)\\n$",TRUE);
the file is like this
_______|_______________________________________________________________________
LMP(0) Addr(0x1) T(M) LMP Len(6) TID(M) Opcode(vers_req)
_______| VersNr(Bluetooth LMP 1.1) CompId(Cambridge Silicon Radio)
_______| SubVersNr(114) Time(18.021s)
_______|_______________________________________________________________________
What I am trying to do select all the lines which are
like the one which has lmp in the begining and not have the new line character in the match that i get.
I am using the search method with the expression and go through the whole file.
but the search method is returning false....
|
|
|
|

|
In your case, I wouldn't read the whole file in at once. I would iterate through it a line at a time using CStdioFile::ReadString().
Since you have used perl, I have a little script here that may help:
use strict;
my $filename = shift || die "need a filename\n";
open( FILE, $filename ) or die "Couldn't open file for reading $!\n";
while( my $line = <FILE> )
{
if( $line =~ /^(LMP\(\d+\).*)$/i )
{
print "======== " . $1 . " =======\n";
}
}
close(FILE);
Notice that my regex changes a few things. First, I dropped your \n character at the end. Second, I am using the \d shortcut instead of [0-9]. I don't think that there should be a difference between those two, so it's just a preference thing there.
I copied and pasted the text you provided into a text file and ran this from the console using perl. Here is my output:
======== LMP(0) Addr(0x1) T(M) LMP Len(6) TID(M) Opcode(vers_req) =======
Notice that there is no carriage return. This is becaus it gets stripped when reading line by line. I believe that CStdioFile::Readstring does the same. I hope this helps a little.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Thanks a lot !!!
I dont know how to thank you for your library.
Yeah you are right my expression was not correct.
I have corrected it and now things seem
to be working.
One question though ,I need to send my appication to other systems,do I need to have the library installed there.
If yes,is it possible to not have to do it.If yes How?.....
I compiled the library using the intructions from your article.
I know there was a message on how to make the library statically linked but I could not understand how to do it?
Thanks again for all your help and the great library.....
|
|
|
|

|
First, I need to set something straight. If, when you say "...thank you for your library", you mean thank your for your article, then you're welcome. However, if you are speaking of Regex++ itself, then I cannot take any credit (though I wish I could ). It is indeed a great library and I've found it extremely useful. You'll have to contact John Maddock and the boost guys to give credit where it's due. I think you should.
Now, as far as your static linking question goes, you are in luck. It is very simple to do. You just need to specify BOOST_REGEX_STATIC_LINK (just copy/paste that line) in your Preprocessor section under "C++" in the project settings. You will see a "Preprocessor dfinitions:" field (in both VC6 and VC7). Just make sure that there is a semi-colon after whatever is in there already and add in that statement. Keep in mind that it is only relevant for release builds, so you don't need to specify it in debug.
Let me know if you need any further help. I'm glad you got it working.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
As far as I go if it were not for you I won't have figured out the library,so for me since you showed me how to install,use it .........its your library.
I have one problem now,the file is comming out as
LMP(8) Addr(0x1) T(M) LMP Len(9) TID(M) Opcode(feat_req) _______| features( EF FD 03 00 00 00 00 00 ) Time(0.035s) _______|_______________________________________________________________________
while this is a single line i need to remove the _ and | from the line so that I have only letters and no other characters.
Is it possible to do that....
Also I for eample need the values of fields Opcode and features,do I have to use Search for them or should I simply
use double parenthesis and then use the values from Match's exp[1.....] for my output.
Thanks again
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A tutorial to demonstrate adding regular expressions to your project using Regex++ from boost.org.
| Type | Article |
| Licence | CPOL |
| First Posted | 17 Jun 2002 |
| Views | 244,254 |
| Downloads | 2,684 |
| Bookmarked | 88 times |
|
|