Re: RegEx question
Re: RegEx question
- Subject: Re: RegEx question
- From: Emmanuel <email@hidden>
- Date: Thu, 19 Feb 2004 16:55:34 +0100
At 12:03 PM +0100 19/02/04, Wim Melis wrote:
>
Hi all,
>
>
For my website generator applescripts, there's one thing I haven't been
>
able to wrap my head around.
>
>
I'd like to build a regular expression search (using Satimage osax) that
>
finds all greater-than en less-than characters that are NOT part of a
>
matching pair of HTML tags, and replace then with the appropriate html
>
codes.
>
>
Any idea how to accomplish this with regular expressions? I'd love to
>
avoid a complex and slow parsing script.
Maybe you can do that with regular expressions, but be aware that they were not designed for that kind of job. It should be more a job for some XML library, I wonder if Late Night Software's XML Tools and/or XSLT Tools can something for you?
At first sight, if I had to do that using regular expressions, I would first change the tag-'<' and '>' into something horrible, then I would change the non-tag '<' and '>' into the < and > and finally I would reverse the horrible thing into the tags. Not clean but may be fast.
Decide for two characters a and b that should not be in the text (I recommend ASCII character of 1 and ASCII character of 4). Then:
------------ untested
set s to change "<([^<>]+)>" into (a & "\\1" & b) in s with regexp
set s to change {"<", ">"} into {"<", ">"} in s
set s to change {a, b} into {"<", ">"} in s
-- I suppose you could group the two last instructions into one
--------------------
Emmanuel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.