Splitting on a pattern or set of delimiters

The standard Applescript split trick (switching text item delimiters) is good for simple delimiters, but gets more complex if you want to split on a pattern, or on a set of alternative delimiters.

Here is one way of specifying a regex or simple set of alternatives for the split.

split(“=”, “holiday-homes=underused housing”)
→ {“holiday-homes”, “underused housing”}

split(“[-=]”, “holiday-homes=underused housing”)
→ {“holiday”, “homes”, “underused housing”}

split(“[-= ]”, “holiday-homes=underused housing”)
→ {“holiday”, “homes”, “underused”, “housing”}


on split(strPattern, strString)
	paragraphs of (do shell script "perl -e 'print join(\"" & return & "\", split(/" & strPattern & "/,\"" & strString & "\"));'")
end split