この目的のために、Satimage sax 3.7.0
利点は正規表現でテキストを見つけることです。
その後、あなたは簡単にfind text
set theText to read file "HD:Path:to:text.txt" as «class utf8» -- replace the HFS path with the actual path
set theResult to {}
set matches to find text "\\d{1,4}<>.*" in theText with regexp and all occurrences
repeat with aMatch in matches
tell aMatch's matchResult
set end of theResult to {text 1 thru 4, text 7 thru -1}
end tell
end repeat
find text
とテキストがレコードを返すフィルタ:
matchLen
:試合の長さ
matchPos
:試合のオフセット(0は最初の文字であります!)
matchResult
:一致する文字列(「使用」パラメータに従ってフォーマットされている可能性あり)
変数theResult
でスクリプトの結果はid
とtext
を含むリストのリストです。 text
は<>
の後に始まりますが、さらに文字をカットすることがあります。
編集:
正規表現は(または私の正規表現の知識があまりにも悪いです)、このテキストを解析することができないようです。
これは、Scripting Additionのない純粋なAppleScriptバージョンです。
set theText to read file ((path to desktop as text) & "description.txt") as «class utf8» -- replace the HFS path with the actual path
set {TID, text item delimiters} to {text item delimiters, ("~~" & linefeed)}
set theMatches to text items of theText
set text item delimiters to TID
set theResult to {}
repeat with aMatch in theMatches
if length of aMatch > 1 then
tell aMatch
set end of theResult to {text 1 thru 4, text 7 thru -1}
end tell
end if
end repeat
返信いただきありがとうございます。私は小さな質問をしました。私がこれをした後、 "テキスト"は最初の行のみを表示し、残りのテキストは "~~"まで表示しません。次のものから1つの項目を「~~」に分割する文字まで、「テキスト」に一連の行を読み込む方法について私を導くことができますか?次は1つのエントリの例のスクリーンショットです:http://i.stack.imgur.com/AqKzS.png –
テキストUTF8はエンコードされていますか?あなたのスクリーンショットに沿ってサンプルテキストでスクリプトをテストしました。 – vadian
UTF8でエンコードされているかどうかはわかりません。スクリプトは正常に機能しましたが、一部のテキストを「テキスト」にフェッチし、「~~」まですべてのテキストをフェッチしません。私がスクリーンショットで送信した強調表示された例については、「匂い」という単語まで「テキスト」を取り出しました –