|
|
Comments and Discussions
|
|
 |

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

|
I'm not sure what type of string object you have your line in at this point, but if you have it in a CString, you can just use CString's Replace function. It would look like this:
sInputString.Replace( "_", "" );
sInputString.Replace( "|", "" );
As far as your other question goes, if I were you, I would just create a method that takes the name of the item you want to grab from the line, and returns its contents. Something like this:
public CString MyClass::GetItemValue( CString key, CString line )
{
CString retStr;
CString pattern = key + "\\(([^)]+)\\)";
RegEx regex( pattern.GetBuffer(10), TRUE );
if( regex.Search( line ) )
{
retStr = regex[1].c_str();
}
return retStr;
}
If you were then to call this method like this:
CString value = GetItemValue( "Opcode", line );
value should now contain feat_req.
I'm not sure if you understand what my regex is doing, so let me explain:
Keep in mind that I am escaping the ( character. So I am also escaping the bacslash (since it is a C++ string). When I send in the key, it gets inserted at the beginning of the pattern string, so when I pass in "Opcode" for example, this:
Opcode\\(([^)]+)\\)
would mean:
match the word Opcode
followed by an opening paren
followed by a capturing open paren
followed by one or more of any letter except a close paren (remember that regexs are greedy, so .+ would match all the way to the last close paren in the line)
followed by a capturing close paren
followed by a closing paren
So now what was captured in regex[1] is feat_req. Does this make sense?
So say you wanted to grab a value for each item in your line, you could now just do this:
CString lmp = GetItemValue( "LMP", line );
CString addr = GetItemValue( "Addr", line );
CString t = GetItemValue( "T", line );
CString len = GetItemValue( "Len", line );
CString tid = GetItemValue( "TID", line );
CString opcde = GetItemValue( "Opcode", line );
CString features = GetItemValue( "features", line );
CString time = GetItemValue( "Time", line );
Notice that I am passing the same line in each time. I believe that this will give you what you need. I haven't tried the regex, so let me know if you have trouble with it.
Good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Thanks a lot for all your help,I have been able to pull it off with your help.Thanks again.
One question though,if I dont want to link with the library statically,which files do I need to packagae with my application so that the program works in the target machine which does not have any vc++ development tool installed.
I mean which regex library files i have to inclue....
|
|
|
|

|
Honestly, I would have no idea how to do that. It's probably the boost_regex dlls, would be my guess. In any case you can pretty much find all of the information you need at the boost site.
Good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
I am trying to use the same code that I wrote earlier into another application but am getting the following error
:\program files\microsoft visual studio\vc98\include\new(35) : error C2061: syntax error : identifier 'THIS_FILE'
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 C2061: syntax error : identifier 'THIS_FILE'
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'
c:\program files\microsoft visual studio\vc98\include\new(41) : error C2061: syntax error : identifier 'THIS_FILE'
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,void *)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl operator new(void))(unsig
ned int)'
c:\program files\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2809: 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2065: '_P' : undeclared identifier
c:\regex++\boost\detail\allocator.hpp(276) : fatal error C1506: unrecoverable block scoping error
Error executing cl.exe.
But the same code is working fine in earlier app!
|
|
|
|

|
Thanks Matt for the clear instructions.
However, I am having a hard time running my debug xll on Excel (says not a valid add-in). I am using VC6 SP5. Works great in release. As per John Maddock's instruction, I did not include the libs in the settings. Any pointers?
With appreciation.
|
|
|
|

|
Thank you for your help.
I have solved the problem.
The problem was that I shouldn't escape \ in My XML file.
By the way, I have one more question.
This is my regular expression:regex="<\s*input\s+[^>]*value\s*=\s*"([^"]*)""
Original Input String<input CLASS=small TYPE=text NAME=cpnc ID=CouponCode VALUE="--Enter redemption code--"onblur="if (value == '') {value = szMERC; getObj('cponnone').checked=true}"onfocus="if (value == szMERC) {value =''}; getObj('cponnew').checked=true" maxlength=80 SIZE=24><input TYPE=HIDDEN NAME=rtyp VALUE=""><input TYPE=HIDDEN NAME=rgto VALUE=""><input TYPE=HIDDEN NAME=wsds VALUE=""></form><form NAME=Cmbo METHOD=POST ACTION="/pub/agent.dll?qscr=cmpk&itid=0&flag=x&rfrr=-726"><input TYPE=HIDDEN NAME=cmrq VALUE=""><input TYPE=HIDDEN NAME=rgto VALUE=""><input TYPE=HIDDEN NAME=htid VALUE=""><input TYPE=HIDDEN NAME=hart VALUE="">
The result<input class=small id=CouponCode onblur="if (value == '') {value = szMERC; getObj('cponnone').checked=true}" onfocus="if (value == szMERC) {value =''}; getObj('cponnew').checked=true" maxLength=80 size=24 value="--Enter redemption code--"
I want to get all the input tag, but just one and the output result is different from the original string.
Please help me.
Thank you.
Sean Lee
|
|
|
|

|
I am currently trying to use Regex++ and I almost got there.
However, I try to use Regex++ with XML parser and I got some problem.
Here is the xml expression.
<subtree name="itinerary" regex="(<\\s*TR\\s*VALIGN=TOP>\\s*<TD\\s*WIDTH=250>\\s*<\\s*B\\s*>[^>]+AM</B>?)"\>
Since "<" and ">" are not valid in XML Syntax, I have to use "<" and ">".
I have loaded the xml string in my program and I got the same string.
char* regex=NULL;
_bstr_t strRegex;
strRegex=pIXMLDOMNode->text;
regex = (char*)malloc(_bstr_t(strRegex).length());
lstrcpy(regex,strRegex);
AfxMessageBox(regex);
But when I compared with following string and I got "FALSE".
char* temp=
"(<\\s*TR\\s*VALIGN=TOP>\\s*<TD\\s*WIDTH=250>\\s*<\\s*B\\s*>[^>]+AM</B>?)";
if(lstrcmp(temp,regex)==0)
|
|
|
|

|
Did you print the two strings out side by side, or step through the debugger to see what they are at that point in the program?
It's just a hunch (and it's possible I don't understand the whole issue), but it looks to me like you are expecting the XML parser to interpolate < and > as < and > . I don't know enough about XML to tell you for sure, but it seems to me that it is probably still looking at < and > as < and >. If this is so, then of course your comparison is going to fail.
This is just a hunch, so let me know if I'm missing something. What XML parser are you using? Let me know and I'll look into that part a little more. Meanwhile, just run it through the debugger and let me know what the two values look like. I hope this is helpful.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Thank you for your help.
I have solved the problem.
The problem was that I shouldn't escape \ in My XML file.
By the way, I have one more question.
This is my regular expression:
regex="<\s*input\s+[^>]*value\s*=\s*"([^"]*)""
Original Input String
<INPUT CLASS=small TYPE=text NAME=cpnc ID=CouponCode VALUE="--Enter redemption code--"
onBlur="if (value == '') {value = szMERC; getObj('cponnone').checked=true}"
onFocus="if (value == szMERC) {value =''}; getObj('cponnew').checked=true" maxlength=80 SIZE=24>
<INPUT TYPE=HIDDEN NAME=rtyp VALUE="">
<INPUT TYPE=HIDDEN NAME=rgto VALUE="">
<INPUT TYPE=HIDDEN NAME=wsds VALUE="">
</FORM>
<FORM NAME=Cmbo METHOD=POST ACTION="/pub/agent.dll?qscr=cmpk&itid=0&flag=x&rfrr=-726">
<INPUT TYPE=HIDDEN NAME=cmrq VALUE="">
<INPUT TYPE=HIDDEN NAME=rgto VALUE="">
<INPUT TYPE=HIDDEN NAME=htid VALUE="">
<INPUT TYPE=HIDDEN NAME=hart VALUE="">
The result
<INPUT class=small id=CouponCode onblur="if (value == '') {value = szMERC; getObj('cponnone').checked=true}" onfocus="if (value == szMERC) {value =''}; getObj('cponnew').checked=true" maxLength=80 size=24 value="--Enter redemption code--"
I want to get all the input tag, but just one and the output result is different from the original string.
Please help me.
Thank you.
Sean Lee
|
|
|
|

|
I've read your doc, thanks for this job.
but i can't solve my pb :
i want to detect and replace, for exemple :
all href="filename.ext"
will be href="[pull name=filename.ext]"
how can i do that ?
nico
|
|
|
|

|
Honestly, I haven't had to do a replacement with this library. However, what you need to look at is the regex_merge or RegEx::Merge functions. Take a look at:
http://www.boost.org/libs/regex/hl_ref.htm#RegEx and note the information about the Merge method.
Also:
http://www.boost.org/libs/regex/template_class_ref.htm#reg_merge - this on has a very good example. It's a bit complex, but you should be able to get the gist.
If I get time, I'll try to work up a simpler example, but let me know if the links above help or not.
Good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
I am having trouble writing the expression to find whole words. How can I search for words that are enclosed inside nonalpha characters? For example, I want to look for . I want to be able to count words like <"ass"> or <-ass2000>. I don't want to list assessment or compass. What is the right syntax to do this? Help appreciated. THanks
|
|
|
|

|
I'm not sure I completely understand your issue here. It might help if you showed me the whole line that you are trying to parse. I'll give it a whirl as is though.
If all you want to match on are alphanumeric sequences, you can use the character class shorthand characters. For instance, if all you wanted to capture were alphanumeric characters (upper and lower case letters and numbers) do something like this:
char* pattern = "\\W.(\\w.)\\W.";
boost::RegEx expr( pattern, FALSE );
.
.
Does this sound like what you are looking for? I haven't tested this, but I think it should work. Let me know.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|

|
Hi,
I am getting an error message "Variable MSVCDIR not set" when I run the command nmake -fvc6.mak.I have checked the vcvars32.bat and the variable has been set to the path C:\ProgramFiles\MicrosoftVisualStudio\VC98 directory.
Could someone please tell me what I might be doing wrong?
Thanks a lot!!
|
|
|
|

|
I can duplicate your problem only by opening a command prompt, changing directories to the build directory and typing 'nmake -fvc6.mak' without typing vcvars32.bat. The only thing I can think of is that:
1. You're not typing vcvars32.bat (which you've already said you are)
2. MSVCDIR is getting set to nothing after you run vcvars32.bat somehow.
Unfortunately, that is the best I can offer right now. I've never seen this problem before and I can't find any reference to it in the newsgroups ( http://groups.google.com ) either.
After you run vsvars32.bat, if you run 'set' at the command prompt, do you see MSVCDir=C:\PROGRA~1\MICROS~3\VC98 or something like that? If so, then I don't know what to tell you.
I hope that someone can provide you with a better answer.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
 |
|
|
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,327 |
| Downloads | 2,684 |
| Bookmarked | 88 times |
|
|