• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Substitute some Strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Substitute some Strings


  • Subject: Re: Substitute some Strings
  • From: Christopher Stone <email@hidden>
  • Date: Mon, 14 Jul 2003 09:52:56 -0500

At 15:41 +0200 07/14/2003, Manfred M. Strasser wrought:

I want to substitute some strings of a TEXT-file or of a HTML-file.
Have anyone any idea?
______________________________________________________________________

Hello Manfred,

Which Mac OS?

How big a file?

On Mac OS 9 I used to use the RegEx osax for this sort of thing; on Mac OS X I'm using the Satimage osax. Both offer pretty good regular expressions, are fairly simple to use for basic stuff, and are capable of doing some remarkably complex find/replace operations.

Eventually I'll get my mind around perl and tcl for Mac OS X, and that'll open up a world of possibilities. But for now it's osaxen all the way.

----- Find:

set t to "Jolly good show!"

try
set findIt to find text "jolly.+ow" in t with regexp and string result without case sensitive
on error
set findIt to false
end try

--> Jolly good show

----- Replace:

set t to "Jolly good show!"
set nt to change "(jolly).+" into "\\1 Roger" in t with regexp without case sensitive

--> Jolly Roger

----- Interesting handler:

on fnd(findStr, usingStr, theText, regexFlags, stringResultFlag)
try
find text findStr in theText using usingStr regexpflag regexFlags string result stringResultFlag with regexp
return true
on error
return false
end try
end fnd

if fnd("()", "\\1", someTEXT, {"EXTENDED", "NEWLINE", "ICASE"}, true) then
set theValue to result
end if

This handler uses the Satimage osax. I discovered to my surprise a while back that the if structure above will evaluate to true/false _and_ will return a _value_ if true, so I can make it do double duty in text filter structures.

In this configuration it only returns a true/false:

set flag to fnd("()", "\\1", someTEXT, {"EXTENDED", "NEWLINE", "ICASE"}, true)

You can simplify this thing quite a lot to suit your needs, but I wanted one handler that'd give me access to all the power of the "find text" command.


Best Regards,

Christopher Stone
_______________________________________________
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.

References: 
 >Substitute some Strings (From: "Manfred M. Strasser" <email@hidden>)

  • Prev by Date: Re: Safari Question
  • Next by Date: Re: OSA Errors -1750 and -1753
  • Previous by thread: Substitute some Strings
  • Next by thread: Login Item that can run a Shell Script
  • Index(es):
    • Date
    • Thread