LoginSignup
9
7

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-01-07
  • 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の機能を使って作成
9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7