comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Regular Expressions
Date: 2000/01/17
Date: 2000-01-17T00:00:00+00:00	[thread overview]
Message-ID: <V6xg4.4527$%Y3.244280@newsread2.prod.itd.earthlink.net> (raw)
In-Reply-To: 38824937.78FFA393@lothrop.de


Kerry W. Lothrop <kerry@lothrop.de> wrote in message
news:38824937.78FFA393@lothrop.de...
> Hello,
>
> I've just started learning Ada and am having problems extracting
> information from a text file (in this case it is a flight logger file).
> I'm used to doing these things in Perl, so I've gotten used to regular
> expressions, which seem to be available through the package GNAT.Regpat.
>
> My first step is to identify the line I'm searching for. It starts with
> an "H", maybe followed by a space, followed by a letter, maybe followed
> by a space, followed by "PLT", maybe followed by a space, followed by
> "PILOT:". I thought this pattern should be "^H ?. ?PLT ?PILOT:". The
> relevant lines in my program are:
>
My recollection of the correct RE for what you've described is
"^H ?[a-zA-Z] ?PLT ?PILOT:"
The "." in you expression says "match _any_ character."
I have not used GNAT.Regpat, so I am at a loss as to why every line should
match.
>    while (not End_Of_File(File => File_Name)) loop
>       Get_Line(File => File_Name, Item => Line, Last => Linlen);
>       if Match(Expression => "^H ?. ?PLT ?PILOT:", Data => Line(1 ..
> Linlen), Size => 10000) then
>          Put_Line(Item => Line(1 .. Linlen));
>       end if;
>    end loop;
>
> The pattern seems to match every line, because the program outputs all
> the lines in the data file. If I just write the pattern "PILOT" it picks
> out the right line. If I write the pattern "^H" it outputs all lines.
>
> What is it I'm doing wrong? Has anyone worked with GNAT.Regpat?
>
> One more thing: Once I have the line, how do I pick out the data after
> the colon?
I would use
Line (Ada.Strings.Fixed.Index (Source => Line, Pattern => ":") .. Linlen);







  reply	other threads:[~2000-01-17  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-16  0:00 Regular Expressions Kerry W. Lothrop
2000-01-17  0:00 ` David C. Hoos, Sr. [this message]
  -- strict thread matches above, loose matches on Subject: below --
1995-02-08 13:50 regular expressions Stefan Knappe
     [not found] <3gucrg$2dn@kaiwan009.kaiwan.com>
     [not found] ` <3h1h74$hnh@Starbase.NeoSoft.COM>
1995-02-06  2:39   ` Michael Feldman
1995-02-06 23:20 ` John Woodruff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox