[ANN]: Script library for regular expressions, text manipulation

RegexAndStuffLib is a script library providing some basic string manipulation commands. There are commands for changing case, splitting and joining strings, various encoding and decoding commands, a range of regular expression commands, and more. It has a dictionary of terminology, to make it simple to use. You can download the library and documentation here:


A few of the commands should be useful for people who have relied on Satimage.osax.

Thanks a lot, Shane!!!

Great, many thanks!

I hope to see more libraries following this naming trend.

  • MathsPlusOtherBitsLib
  • StringsAndRantsLib
  • ListsNShitLib

One difficulty with this claim is that the library uses different keywords and parameters from Satimage, so anyone who’s relied on Satimage in the past will have to learn new stuff. This being so, they might just as well learn the relatively simple underlying AS and ASObjC commands, which have been available to scripters for some time now. It would both empower them and reduce the incidence of non-standard and occasionally non-sensical terminology in scripts, which would in turn make the scripts easier for others to understand and increase the chances of people who need help with scripts actually receiving it on the fora.

I think that’s a straw-man argument. A lot of people have used Satimage.osax primarily for regular expressions and stuff like case conversion, and the library simply provides some of those functions. I made no claim of similarity in implementation.

I wrote a lot of it initially for myself – I think I understand the underlying commands reasonably well, but I still appreciate convenience. And especially in terms of editing older code, there’s a lot to be said for keeping ASObjC code separate.

That said, the code is all there for people to read, use and adapt, and similar code for much of it has been posted here many times already, often by me, for those who want to learn it. I suspect you overestimate people’s enthusiasm for learning stuff like ASObjC (something I’ve obviously been guilty of too).

If you have suggestions for improving the terminology, I’d welcome them. But I’m struggling to understand what “non-standard” means in this context. I mean, unless I’ve missed something, |⌘| is a little off the beaten track :wink:

I’ve read that several times, and each time I think I know what you mean, I suspect I’ve misunderstood. A script that uses commands and parameters documented in a standard scripting dictionary is harder for a scripter to understand than blocks of essentially Objective-C code re-written in verbose AppleScript?

FYI, Version 1.0.2 is now available.

This version introduces performance improvements. In particular, the regex search command is faster — significantly so if you specify a replace template, or capture groups is either unused or a single integer.

Available same place, same name.

Shane, I have found your RegexAndStuffLib to be very helpful and instructive. However, my attempt to convert a list of strings to upper case erred.

use scripting additions
use script "RegexAndStuffLib" version "1.0.2"
set capsText to uppercase from {"one", "two", "three"} --> "The variable theString is not defined."

In your RegexAndStuffLib.scptd, v 1.0.2, modified July 24, 2019 at 5:40 PM, as listed in Finder’s Get Info, on line 54, I noted [format] return (theString’s valueForKey:“localizedUppercaseString”) as text[/format]
I, however, could not find a prior definition of the theString variable. Could that be the reason for the “uppercase from” command to err?
I noted similar parallels to this line of code utilizing theString in other parts of your RegexAndStuffLib.scptd.

Of no scripting importance, but while I was reading your script, I noted that the Description heading remained as RegexAndStuffLib v1.0.1 rather than v.1.0.2.This was of no scripting concern, but might be of interest in keeping readers from confusing versions.

In any regard, thank you for instructing all of us to be better Applescript coders.

Yes, the list-handling code is borked because of last-minute changes. Version 1.0.3 is now available, with the problem fixed. Let me know if you find any other issues. Thanks.

FYI, Version 1.0.4 is now available. Itfixes a bug in the regex search once command, where it returns an array rather than a list when multiple capture groups are specified.

Hi Shane,
just a small hint. The default for match case in all regex functions is false instead of true written in the dictionary.

Thanks for your great collection.

Indeed it is – thanks for the correction!

Hi Shane,
it would be nice if the regex commands can handle also list’s instead of text only. Like the satimage find text or change commands.

Maenwhile i use my custom Handler:

use AppleScript version "2.4" -- macOS 10.10 or later
use framework "Foundation"
use scripting additions
use script "RegexAndStuffLib" version "1.0.4" -- /Library/Script Libraries/RegexAndStuffLib.scptd

--return my changeRegexp("1234.tif", "^(..).*", "$1")
--return my changeRegexp({"1234.tif", "abcd.tif"}, "^(..).*", "$1")

on changeRegexp(theObject, ExpressionString, ReplaceExpressionString)
	set objectClass to class of theObject
	if objectClass is list then
		local resultList
		set resultList to {}
		repeat with anItem in theObject
			set end of resultList to my changeRegexp(contents of anItem, ExpressionString, ReplaceExpressionString)
		end repeat
		return resultList
	else if objectClass is string or objectClass is text then
		return regex change theObject search pattern ExpressionString replace template ReplaceExpressionString
		return theObject
	end if
end changeRegexp

Maybe you’d like to put something like that in.

I’ll consider it, but I’m not sure I can bring any value to it that you can’t really do with a simple loop.

I guess I’m just a bit baffled as to why some people prefer to bury explanatory terminology in semi-opaque handlers rather than use the commands directly when needed. I mean, I know it can be a little less typing, and if you use the same stuff all the time you have familiarity on your side. But the curious thing is that in my experience people don’t tend to use libraries unless they include terminology – and then many quickly bury it.

Anyway, v1.0.5 is available with the dictionary fixed.

Was also only a consideration, since I know that many people work or have worked with the Satimage.
Personally, I can live with your library as it is.
Everything else I build myself.

I’m very new to AppleScriptObjC, but I haven’t finished reading your book ‘Everday AppleScriptOpjC’ yet, I’m still at it.

Many thanks for the new version 1.0.5

This is now available in version 1.0.6. Get it here:


Sounds nice. Thank you.

Shane, your script libraries are awesome. I am using the RegexAndStuffLib and FileManagerLib on a regular basis.

I notice you are updating them on a regular basis. Would it be possible to have an “Updated: [date]” on each of the libraries listed on the libraries page here?:


That would help me keep up with all the great changes.

Good idea – I’ll try to remember it next update.