メインコンテンツまでスキップ
バージョン:25.2

match

  • operator keyword, new in 1.65, for invoking the matchingProperties function

    • properties of x that match those of y
  • function

  • new in 1.81

  • The match  and everyMatch functions have identical syntax to the offset, range, everyOffset, and everyRange functions, but can only be used to locate a pattern, not a simple text string. When the match function finds a match for a pattern, it returns a match property list containing a number of properties, depending on the pattern. For a pattern with no capture groups, it will contain "text" and "text_range" properties with the matched text and the range where that text was found.

         put the match of <3 digits> in "123456789" -> (text:"123", text_range:"1" to "3")

    If the pattern being matched contains one or more capture groups, the property list returned by the match function will include two additional properties for each group that was matched. The first will be the name of the group, with the matched text for that group as its value. The second will be the name of the group with "_range" appended to it, with the range where that group was matched as its value.

  • chunk type
  • new in 1.81
  •     The match chunk type will return a pattern match property list:
         put the second match of <3 digits> in "987654321"
-> (text:"654", text_range:"4" to "6")

    Unlike other text chunk types, requesting a range of matches or occurrences will return a list of values rather than a substring of the string:

         put instances 3 to 5 of <digit> in "V2.7 for 4/3/18"
-> (4,3,1)
put the first 3 occurrences of <max digits> in "42-16gh9-88"
—> (42,16,9)
put the last 2 matches of <max digits> in "42-16gh9-88"
—> ((text:"9", text_range:"8" to "8"),(text:"88", text_range:"10" to "11"))

    When used as a container (to put something before, into, or after the chunk), occurrence and match chunks behave like other types of chunks, identifying a range of characters in the string.

         set text to "[a]hello[b]bonjour[c]hola[d]"
set marker to <"[", character, "]">
put occurrences 2 to 3 of marker in text
—> ("[b]","[c]")
put "$$$" into occurrences 2 to 3 of marker in text
put text
—> "[a]hello$$$hola[d]"