将正则表达式结果保存到变量

Saving regex results to variable

我在带有 Satimage osax 的 applescript 中使用正则表达式。它工作正常,但我希望能够将返回的匹配项保存到一个变量中以供使用

这是我在 applescript 编辑器的回复部分看到的:

find text "(?i)(nhl|nfl|ncaa)" in "NFL games.pdf" with regexp
    --> {matchPos:0, matchLen:3, matchResult:"NFL"}

我能够使用对话框显示结果,但无论我尝试什么,我都无法将其保存到变量中。

作品:

display dialog matchResult of (find text "(?i)(nhl|nfl|ncaa)" in theName with 
regexp)

无效:

set matchResult of (find text "(?i)(nhl|nfl|ncaa)" in theName with regexp) to 
keywordResult
set (matchResult of (find text "(?i)(nhl|nfl|ncaa)" in theName with regexp)) to 
keywordResult

如有任何帮助,我们将不胜感激!

瑞安

set keywordResult to matchResult of (find text "(?i)(nhl|nfl|ncaa)" in theName with regexp) 

copy matchResult of (find text "(?i)(nhl|nfl|ncaa)" in theName with regexp) to keywordResult

您还可以:

set keywordResult to (find text "(?i)(nhl|nfl|ncaa)" in "NFL games.pdf" with regexp)
matchResult of keywordResult --> "NFL"
matchLen of keywordResult --> 3
matchPos of keywordResult --> 0