Irregularities

hullo all,

I’ve been searching for some information on Applescript wrt regular expressions and it’s been tough. So I thot I’d ask directly here. So. Does Applescript have regex capabilities built in or does it do that kind of thing (search a bag of data for a particular pattern) in some other way? I searched this forum and it seems that mebbe if you need regex stuff, you’d need to use some unix trick like grep or something.

The scenario I’m thinking of is a deal where I have been given some kind of csv file (or dbf file?) and I need to take the contents of that file and compare it with another (if there’s a match, then there’s some action).

Now, I mention regex as if I know what I’m talking about (and perhaps my question exposes my ignorance anyway), but I don’t. I am looking for the right language “religion” for me, one that is deep enough in features without an overwhelming syntax. This looks a prime suspect so far, but…y’know, just askin. :confused:

p.s. Is there any way that a note can be put up at the top of the forum (or someplace prominent) so that newbies like me know that you have to join the forum first in order to search it (i found out by trying it, a half-wild guess)? :stuck_out_tongue:

Nope, AppleScript’s text handling facilities are extremely limited, and for stuff like regexes you need to use a third-party solution.

  1. There are one or two osaxen that include regex-based find/replace (e.g. Satimage.osax), but I don’t think there’s any that are Unicode-aware unfortunately so if that’s a requirement then you’re out of luck there.

  2. Calling something via ‘do shell script’ is always an option, though there are caveats there too. grep definitely isn’t Unicode-aware, and it’s only good for certain tasks. A better option would be to use Perl/Python regexes via ‘do shell script’, though to roll your own you’ll need to know something of those languages and remember to convert text encodings where appropriate. In all cases, be aware that ‘do shell script’ doesn’t support stdin and there’s a limit on the size of text you can pass on the command line itself (a few hundred KB at most), so for processing larger amounts of text you’ll need to write it to a temp file first and have your shell script read from that.

  3. As an addendum to #2, AppleMods’s RE library already provides a convenient wrapper around Perl’s regex facilities, though it’s currently limited in the amount of text it can handle.

  4. There are some scriptable text editors (e.g. TextWrangler, Smile) that support regex-based find/replace and are unicode aware. These may not be appropriate in some situations, mind you (i.e. users may not appreciate text editor windows bouncing around their screens each time the script runs).

  5. You could use a scriptable FBA (faceless background application) which’ll run invisibly, e.g. TextCommands provides a unicode-savvy ‘search’ command with optional regex support.

HTH

has

Wow. Thanks hhas. Very thorough. I did find some kind of AppleScript command called searchReplaceText, but obviously that can only do so much. This is good news. I can work with this. The investigation continues…

Sorry, one more question hhas (or anyone): what about trying g/awk? Any issues to be wary of in trying ‘do shell script’ with g/awk?