
-----Original Message----- From: Jadhav, Rahul (Rahul) Sent: Tuesday, August 03, 2004 12:33 PM To: 'boost@lists.boost.org' Subject: problem with subexpressions
Hi All, I am not sure if I m doing wrong or there is some problem with library. I want to extract "f23" and "this is corresponding text" from string "f23 : this is corresponding text" so I have written regular expression "(f[0-9]{1,})\\s*:\\s*(.*)" so that in match[0] is should have index information for first subexpression and should give me indices of "f23" but it gives me whole string as first subexpression.
It may be my mistake but I have spent 2 days and nights on this thing so I thought I should post it. Also I tried to find out a topic related to subexpressions on the mailing list but could not find one. below is the code.
regex_t preg; regmatch_t match[3];
if(regcompW(&preg,L"(f[0-9]{1,})\\s*:\\s*(.*)",REG_ICASE|REG_EXTENDED)==0) AfxMessageBox(L"successful"); CString str=L"f23 : this is corresponding text";
wchar_t* ptr=str.GetBuffer(str.GetLength());
if(regexecW(&preg,ptr,3,match,0)!=REG_NOMATCH) { int i=0; while(i<3) { wchar_t arr[200]; wcsncpy(arr,(ptr+match[i].rm_so),match[i].rm_eo-match[i].rm_so); arr[match[i].rm_eo-match[i].rm_so]='\0'; ptr=ptr+match[i].rm_eo; AfxMessageBox(arr); //AfxMessageBox(ptr); i++; } }
Thanks Rahul Jadhav