<regex> anybody?

40 views
Skip to first unread message

#5

unread,
Aug 27, 2021, 9:14:36 PM8/27/21
to wx-users
Does anybody know how to use the <regex> lib , how to compile, match and get matches
The other one <wxpcre.h> doesn't seem to be working

Igor Korot

unread,
Aug 27, 2021, 9:20:22 PM8/27/21
to wx-u...@googlegroups.com
Hi,

On Fri, Aug 27, 2021 at 8:14 PM #5 <no5so...@gmail.com> wrote:
>
> Does anybody know how to use the <regex> lib , how to compile, match and get matches
> The other one <wxpcre.h> doesn't seem to be working

What exactly doesn't work?
Can you be more specific?

Thank you

>
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/7c3faf2f-5f82-4a41-a26f-8bb1ea0016a3n%40googlegroups.com.

Vadim Zeitlin

unread,
Aug 28, 2021, 8:39:59 AM8/28/21
to wx-u...@googlegroups.com
On Fri, 27 Aug 2021 18:14:36 -0700 (PDT) #5 wrote:

> Does anybody know how to use the <regex> lib , how to compile, match and
> get matches

If you want to use std::regex, please refer to the standard library
documentation, this has nothing to do with wx. If you want to use wxRegEx,
which is PCRE-based since very recently, you have its documentation at
https://docs.wxwidgets.org/trunk/classwx_reg_ex.html

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

#5

unread,
Aug 29, 2021, 7:28:34 AM8/29/21
to wx-users
please disregard my comment. i will use wxRegEx instead

#5

unread,
Aug 29, 2021, 9:00:56 AM8/29/21
to wx-users
// Now i'm using wxRegEx and this does'nt match
wxString input(wxT(":irc.example.net 372 mynick :- #Unicode  The Unicode character coding system"));
res = regex.Compile(wxT("^:(\\S+)\\s(\\d{3})\\s(.*):(.*)$"));
if (res && regex.Matches(input))
{ ....
// even though it works on here https://regex101.com/r/ezPxTQ/1/
what am i doing wrong?
Thanks in advance;

Vadim Zeitlin

unread,
Sep 3, 2021, 6:26:58 PM9/3/21
to wx-u...@googlegroups.com
On Sun, 29 Aug 2021 06:00:56 -0700 (PDT) #5 wrote:

> // Now i'm using wxRegEx and this does'nt match
> wxString input(wxT(":irc.example.net 372 mynick :- #Unicode The Unicode
> character coding system"));
> res = regex.Compile(wxT("^:(\\S+)\\s(\\d{3})\\s(.*):(.*)$"));
> if (res && regex.Matches(input))
> { ....
> // even though it works on here https://regex101.com/r/ezPxTQ/1/
> what am i doing wrong?

No idea, but your regex works for me:

---------------------------------- >8 --------------------------------------
% cat wxregex_test.cpp
#include <wx/init.h>
#include <wx/crt.h>
#include <wx/regex.h>

int main(int argc, char **argv)
{
wxInitializer init;
if ( !init.IsOk() ) {
fprintf(stderr, "Failed to initialize wxWidgets.\n");
return 3;
}

if ( argc != 3 ) {
fprintf(stderr, "Usage: %s <pattern> <subject>.\n", argv[0]);
return 2;
}

wxRegEx rx;
if ( !rx.Compile(argv[1], wxRE_ADVANCED) ) {
fprintf(stderr, "Failed to compile regex /%s/.\n", argv[1]);
return 1;
}

if ( !rx.Matches(argv[2]) ) {
printf("Regex /%s/ doesn't match \"%s\".\n", argv[1], argv[2]);
return 1;
}

wxPrintf("Matched \"%s\" with %zu captures.\n", rx.GetMatch(argv[2]), rx.GetMatchCount());

return 0;
}
% g++ -g -Wall -o wxregex_test wxregex_test.cpp `wx-config --cxxflags --libs base`
% ./a.out "^:(\S+)\s(\d{3})\s(.*):(.*)$" ":irc.example.net 372 mynick :- #Unicode The Unicode character coding system"
Matched ":irc.example.net 372 mynick :- #Unicode The Unicode character coding system" with 5 captures.
---------------------------------- >8 --------------------------------------

Gunter Königsmann

unread,
Sep 4, 2021, 2:04:08 AM9/4/21
to wx-u...@googlegroups.com, Vadim Zeitlin
Might it be that if it fails the input was converted from Unicode to codepage-something before passing it to the regex test?

Fernando Fiore

unread,
Sep 4, 2021, 3:05:59 PM9/4/21
to wx-u...@googlegroups.com
Thanks for the help.
Fernando

Livre de vírus. www.avg.com.
Reply all
Reply to author
Forward
0 new messages