正規表現による置き換えは以下のようにして行います。
AppleScript自体は正規表現の機能を持っていないので、様々なエンジンを介して実現する方法があるらしいのですが、私はCocoaの機能を呼び出してて使う方法を採用しました。
set tempStr to my repString(元文字列, “正規表現パターン”, “置き換え文字列”)
use scripting additions
use framework “Foundation”on repString(originalStr as text, pattern as text, newString as text)
set regularExpression to current application’s NSRegularExpression’s regularExpressionWithPattern:pattern options:0 |error|:(missing value)
return (regularExpression’s stringByReplacingMatchesInString:originalStr options:0 range:{location:0, |length|:count originalStr} withTemplate:newString) as text
end repString