Help us understand the problem. What is going on with this article?

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の機能を使って作成
szk-3
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away