I'm trying to eliminate TextCommands from my scrips where possible.
The main reason I picked up on TextCommands in the first place was for the regex search and/or replace functions. To this end, it has worked great.
But, as a programmer, I'm always looking for a better or easier way to do things. And I hate it when I don't understand when something doesn't work the way I think it should, so now I'm trying to understand why this piece of script doesn't work. (Thanks, Chris Stone, now you've got me off on a tangent - huge :>)
I have stripped a simple piece of script code from a much larger script to make an example and have hard-coded some variables for this example. Here's my script piece:
property appTitle : "Test Parent Container"
set RegExpOpts to {"MULTILINE", "IGNORECASE"}
set f_Fix to "Macintosh HD:HD1:Misc: New: Fix:" set HTML_folder to "Macintosh HD:HD1:Misc: New: Fix:MyFolder: HTML" set mess to "Original string:" & return & HTML_folder -- debug
-- via TextCommands tell application "TextCommands" set x to search HTML_folder for f_Fix replacing with "" set ParentContainerName to search x for ":(.)*$" replacing with "" with regex end tell
set mess to mess & return & return & ParentContainerName & " <== from TextCommands" -- debug
-- via OSAX set x to change f_Fix into "" in HTML_folder set ParentContainerName to change ":(.)*$" into "" regexpflag RegExpOpts in x with regex
set mess to mess & return & return & ParentContainerName & " <== from OSAX" -- debug
display dialog mess with title appTitle -- debug
When I run this script, I get:
Original string: Macintosh HD:HD1:Misc: New: Fix:MyFolder: HTML
MyFolder <== from TextCommands
MyFolder: HTML <== from OSAX
My question: Why did the line:
set Parent_Container to change "[:](.)*$" into "" regexpflag RegExpOpts in x with regex
not strip the ": HTML" from the string x under the OSAX like it did under TextCommands?
My understanding is that it should find the first colon and then replace from that colon to the end of the string with an empty string. So what am I doing that's wrong?
If I can't understand this, I'll never get the more complex searches I have to correct (yes there are other ways to do what I'm doing - text delimiters, etc). I'm not interested in another method - the point is to understand why this specific instance doesn't work. It goes to a deeper understanding of the OSAX itself.
TIA,
Jim Brandt |