Edited at

Cocoaの機能を使って正規表現で文字列を置き換えるAppleScriptハンドラ

More than 3 years have passed since last update.



  • do shell scriptを使わないとできなかった正規表現の文字列置き換え

  • AppleScript上でCocoaの機能を使えるようになった


regexReplace.scpt

use framework "Foundation"

my regexReplace("<p>あいうえお</p>", "<.+?>", "")
--> "あいうえお"

on regexReplace(aText as text, pattern as text, replacement as text)
--require framework: Foundation
set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|:(missing value)
return (regularExpression's stringByReplacingMatchesInString:aText options:0 range:{location:0, |length|:count aText} withTemplate:replacement) as text
end regexReplace



更新履歴


  • 2016-01-07: Cocoaの機能を使って作成