From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,40f0399c242060cd X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Regular Expressions Date: 2000/01/17 Message-ID: #1/1 X-Deja-AN: 573608721 Content-Transfer-Encoding: 7bit References: <38824937.78FFA393@lothrop.de> Content-Type: text/plain; charset="iso-8859-1" X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-ELN-Date: Sun Jan 16 20:44:37 2000 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 948084277 158.252.123.64 (Sun, 16 Jan 2000 20:44:37 PST) Organization: EarthLink Network, Inc. MIME-Version: 1.0 NNTP-Posting-Date: Sun, 16 Jan 2000 20:44:37 PST Newsgroups: comp.lang.ada Date: 2000-01-17T00:00:00+00:00 List-Id: Kerry W. Lothrop 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);