ArqWx::RegEx class : extension for wxRegEx

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

ArqWx::RegEx class : extension for wxRegEx

Post by TrV »

ArqWx::RegEx class : extension for wxRegEx


Hi,

Here are some shared code :
RegEx (namespace ArqWx) is a C++/wxWidgets class which extends capacities of wxWidgets regular expressions
management. It is designed to work with wxWidgets' wxRegEx class, and adds these functionalities:
- processes whole text with a single regex pattern, thus it can extracts as many matches are
contained into whole text;
- extracts named groups.

For details, please read included text file.


-----


Name grouping

Doc extract:

example 1:

Code: Select all

1 ArqWx::RegEx myTRE("^.+/(?<filename>[^.]+).(?<extension>[^?]+).+");
2 ::wxMessageBox(myTRE.Groups("http://www.site.net/Smtg/Another/Forums/AddPost.aspx?tabindex=1", "filename"));
3 ::wxMessageBox(myTRE.Groups("http://www.site.net/Smtg/Another/Forums/AddPost.aspx?tabindex=1", 2));
Line 2 will display "AddPost".
Line 3 will display "aspx".


example 2:

Code: Select all

1 ArqWx::RegEx myTRE("^.+/(?<filename>[^.]+).(?<extension>[^?]+).+", "http://www.site.net/Smtg/Another/Forums/AddPost.aspx?tabindex=1");
2 ::wxMessageBox(myTRE.Groups("extension"));
3 ::wxMessageBox(myTRE.Groups(1));
Line 2 will display "aspx".
Line 3 will display "AddPost".


-----


Whole text processing

Doc extract:

example 1:

Code: Select all

1 ArqWx::RegEx myTRE("/([^/]+)");
2 ::wxMessageBox(wxString::Format("%d", myTRE.GetTotalMatchCount("http://www.site.net/Smtg/Another/Forums/AddPost.aspx?tabindex=1")));
3 ::wxMessageBox(myTRE.GetTotalMatch("http://www.site.net/Smtg/Another/Forums/AddPost.aspx?tabindex=1", 2));
Line 2 will display "5".
Line 3 will display "Smtg".


example 2:

Code: Select all

1 ArqWx::RegEx myTRE("/([^/]+)", "http://www.site.net/Smtg/Another/Forums/AddPost.aspx?tabindex=1");
2 ::wxMessageBox(wxString::Format("%d", myTRE.GetTotalMatchCount()));
3 ::wxMessageBox(myTRE.GetTotalMatch(4));
Line 2 will display "5".
Line 3 will display "Forums".


----

I cannot guarantee this class is bug-free, but all tests i have performed were ok.

Feel free to use this class and to send me some reports, especially if you find bugs !! :)
Attachments
ArqWx.RegEx_src.zip
(4.25 KiB) Downloaded 173 times
ArqWx.RegEx_example.zip
(5.96 KiB) Downloaded 169 times
Post Reply