Page 1 of 1

wxRegex: Capturing matches in filecontent seperated by a \n

Posted: Mon Aug 27, 2012 5:03 pm
by extreme001
Hi!

I have a file, a configfile and want to read the settings and values with a regular expression, seperated by a newline.
I always get one match over the complete string. This is the expression:

Code: Select all

wxRegEx regex(_T("(?pw)^(SaveMy\\w+|Color)=(.+)$"), wxRE_ADVANCED);
And this is file content:

Code: Select all

SaveMySetting1=Value1
SaveMySetting2=Value2
Color=red
How can i get all matches line by line (like find next) without reading the file line by line and just match the regex over the complete content?

Is it possible?


Thank you very much!

Re: wxRegex: Capturin matches in filecontent seperated by a

Posted: Mon Aug 27, 2012 6:13 pm
by Mojo
I guess wxFileConfig is more suitable http://docs.wxwidgets.org/stable/wx_wxfileconfig.html

Re: wxRegex: Capturin matches in filecontent seperated by a

Posted: Mon Aug 27, 2012 7:11 pm
by extreme001
Hey! Thank you! I know that i can do it the way you described, but i want to know to do with wxRegEx. Any idea?

Re: wxRegex: Capturin matches in filecontent seperated by a

Posted: Mon Aug 27, 2012 7:56 pm
by doublemax
What is the "(?pw)" in the beginning supposed to do? I've never seen that syntax.

This one worked for me:

Code: Select all

wxString s("SaveMySetting1=Value1\nSaveMySetting2=Value2\nColor=red\n");
wxRegEx regex(_T("^(SaveMy\\w+|Color)=(.+)$"), wxRE_ADVANCED|wxRE_NEWLINE);
while( regex.Matches(s) ) {
  wxLogMessage( wxT("%s => %s"), regex.GetMatch(s, 1), regex.GetMatch(s, 2) );
  // wxRegEx doesn't support multiple matches, so delete the last match and search again
  s.Replace(regex.GetMatch(s, 0), wxEmptyString);
}

Re: wxRegex: Capturin matches in filecontent seperated by a

Posted: Tue Aug 28, 2012 9:17 am
by extreme001
Thank you very much! That's what i was looking for. I used the wrong flags.

Have a nice day.