wxRegEx does not work properly?!?!?

Fibre Optic fibre_optic at go2.pl
Fri Sep 1 03:53:16 PDT 2006


Michael Wetherell wrote:
> On Wednesday 30 Aug 2006 14:41, Michael Wetherell wrote:
>> A couple of other problems: fgets will leave a trailing newline in
>> the string, and casting a char[] to a wxString isn't allowed (you can
>> just assign it in a non-unicode build).
> 
> On Wednesday 30 Aug 2006 17:58, Fibre Optic wrote:
>> My understanding is: if i enter "^[^@]*@([^@]+)@" it should
>> work...but it does NOT :-( Hard coded "^[^@]*@([^@]+)@" works good.
>> What is going on?
> 
> Yes, remove the last character to get rid of the newline which fgets 
> appends. Also the static_cast is invalid and isn't needed.
> 

the code is as follows:

#include <wx/wx.h>
#include <wx/regex.h>
#include <stdio.h>

int main(int argc, int arg[])
{
     char regex[255];
     wxString cookieField = 
"Njky=gg6435345b at APC216@172.16.1.15 at D34fD$F$F$F";

     wxString userID;
     char *p;

     printf("Enter cookie RegEx and press enter: ");
     fgets(regex, sizeof(regex), stdin);

     //now remove \n
     if ((p = strchr(regex, '\n')) != NULL);
       *p = '\0';

     //static wxRegEx cookieRegEx(wxT("^[^@]*@\([^@]\+\)@"));
     //static wxRegEx cookieRegEx(wxT("^[^@]*@([^@]+)@"));
     wxRegEx cookieRegEx(wxT(regex));

     if (cookieRegEx.Matches(cookieField)) {
      userID = cookieRegEx.GetMatch(cookieField, 1);
      printf("User ID: %s\n", userID.c_str());
     }
}

And it works now with the following RegEx' "^[^@]*@([^@]+)@" !!!  Thank 
you all of you!!!

Regards,
Fibre Optic






More information about the wx-users mailing list