From: 19.krause.70@googlemail.com
Subject: gnat_regpat and unexpected handling of alnum and unicode needed
Date: Sun, 17 Feb 2019 03:24:06 -0800 (PST)
Date: 2019-02-17T03:24:06-08:00 [thread overview]
Message-ID: <69abfba5-0dae-493a-b39c-91fcf7be8c75@googlegroups.com> (raw)
Hello All,
I was strugeling about a behavior in gnat-repat which is different from the behavior of egrep for example and different from the behavior I expect.
The expression [[:alnum:]] matches the underscore in gnat_regpat but not in egrep. It feels much more natural to don't match the underscore like egrep does. And I think it is more posix compliant.
Question is why?
Now I could simply use [[:alpha:][0-9]]+ instead but then I got to my second question: How do I handle unicode strings with gnat_regpat, because [[:alpha:]] seems to match only ascii a-zA-Z. Some sample code (Safe as utf-8 text, compiled with -gnatW8):
with Ada.Text_IO;
with Gnat.Regpat;
procedure gnat_regpat_test is
test1 : constant String := "foo_bar";
test2 : constant String := "fööbär";
regexp1 : constant String := "^[[:alnum:]]+$";
regexp2 : constant String := "^[[:alpha:][0-9]]+$";
begin
if Gnat.Regpat.Match(Expression => regexp1, Data => test1) then
Ada.Text_IO.Put_Line(test1 & " Matched regexp1 " & regexp1 & "!");
else
Ada.Text_IO.Put_Line(test1 & " doesn't Match regexp1 " & regexp1);
end if;
if Gnat.Regpat.Match(Expression => regexp2, Data => test1) then
Ada.Text_IO.Put_Line(test1 & " Matched regexp2 " & regexp2 & "!");
else
Ada.Text_IO.Put_Line(test1 & " doesn't Match regexp2 " & regexp2);
end if;
if Gnat.Regpat.Match(Expression => regexp1, Data => test2) then
Ada.Text_IO.Put_Line(test2 & " Matched regexp1 " & regexp1 & "!");
else
Ada.Text_IO.Put_Line(test2 & " doesn't Match regexp1 " & regexp1);
end if;
if Gnat.Regpat.Match(Expression => regexp2, Data => test2) then
Ada.Text_IO.Put_Line(test2 & " Matched regexp2 " & regexp2 & "!");
else
Ada.Text_IO.Put_Line(test2 & " doesn't Match regexp2 " & regexp2);
end if;
end gnat_regpat_test;
Best Regards,
Hubert
next reply other threads:[~2019-02-17 11:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-17 11:24 19.krause.70 [this message]
2019-02-17 12:50 ` gnat_regpat and unexpected handling of alnum and unicode needed Simon Wright
2019-02-17 13:15 ` 19.krause.70
2019-02-17 13:21 ` 19.krause.70
2019-02-17 13:09 ` 19.krause.70
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox