Regex (MatchText) speed

Mark Brownell gizmotron at earthlink.net
Thu Jun 24 01:08:04 EDT 2004


On Wednesday, June 23, 2004, at 06:50  PM, Troy Rollins wrote:

> I only wish I were parsing any kind of "formed" text. The stuff I am 
> parsing is more like chaos. It can be anything from plain English 
> error messages, to server directory lists, to date and time formats... 
> with NO consistent formatting.
>
> The first job of my parser is to simply try to determine what the heck 
> it is parsing. I currently have it functional, using if-else ifs, 
> contains, etc. I'm considering replacing ALL of that with one powerful 
> matchText, but if that only ends up costing me time rather than saving 
> it...

-- put getElement("<record>", "</record>", myText) into theElement
-- put getElementsArray("<record>", "</record>", myText) into theArray

These two functions work with any text for the start spot and any text 
for the end spot.

If you were parsing an email message you could use something like this:
-- use the getElement() function from my last message.
-- put getElement("<record>", "</record>", tZap) into theElement

From: Troy Rollins <troy at rpsystems.net>
Date: Wed Jun 23, 2004  6:50:59  PM US/Pacific
To: How to use Revolution <use-revolution at lists.runrev.com>
Subject: Re: Regex (MatchText) speed
Reply-To: How to use Revolution <use-revolution at lists.runrev.com>

put getElement("From:", "Date:", yourEmail) into mFrom
put getElement("Date:", "To:", yourEmail) into mDate
put getElement("To:", "Subject:", yourEmail) into mTo
put getElement("Subject:", "Reply-To:", yourEmail) into mSubject

These example above would require striping the line returns.

To get the body of the email you could use:
put getElement("Reply-To:", "From:", yourEmail) into mBody
...and strip the first line of mBody

Mark



More information about the use-livecode mailing list