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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,45d3652405dab08f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-29 09:15:24 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!newsfeed.direct.ca!look.ca!newsfeed.bc.tac.net!news.bc.tac.net!not-for-mail Sender: blaak@TORUS Newsgroups: comp.lang.ada Subject: Re: Regular expressions??? References: <3B3C48FB.E40ECFA9@ida.his.se> From: Ray Blaak Message-ID: Organization: The Transcend X-Newsreader: Gnus v5.7/Emacs 20.7 Date: 29 Jun 2001 09:13:50 -0700 NNTP-Posting-Host: 208.181.209.61 X-Complaints-To: news@bctel.net X-Trace: news.bc.tac.net 993831305 208.181.209.61 (Fri, 29 Jun 2001 09:15:05 PDT) NNTP-Posting-Date: Fri, 29 Jun 2001 09:15:05 PDT Xref: archiver1.google.com comp.lang.ada:9261 Date: 2001-06-29T09:13:50-07:00 List-Id: Michael Andersson writes: > I'm trying to write a simple XML-parser and I wonder how regular > expressions in Ada works. Can I use variables as in Pearl so that these > are assigned a value according to the values found in the string. Say > for example that I have a file looking like this: > > I want to extract Michael, 7989438 and 22 from the string above and > assign these to some variables. Is it possible to use regular > expressions in Ada to do this or do I have to use procedure/functions > from the Ada.Strings package? For this problem, it is in fact easier and faster to parse the XML properly to extract the relevant bits. That is, make a pseudo-state machine that looks for <, >, =, ", />, etc, performing callbacks or inserting into an XML tree structure when the relevant bits are recognized. If you are going to hunt around for a RE package in Ada, you can also hunt around for an XML package. Otherwise, writing an XML parser is a lot easier than writing a RE processor. Regular expressions are often mismused where a real parser would be more appropriate. Consider an RE that can extract bits from this line: Fine. Now, would that RE work for this: or this: which are both equivalent semantically? REs work best with line oriented fix-formatted data. Free-form data tends to break REs. -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, blaak@infomatch.com The Rhythm has my soul.