The pick Command

This command has several forms:

Pick Items

Syntax

pick items at|from? from? start to end from array inclusive|exclusive?

pick item at? [...]

Description

Selects items from array using Array.slice. By default, it will include start but not end. You can use inclusive or exclusive to override this behavior. If end is omitted, it will return an array containing just one item.

set arr to [10, 11, 12, 13, 14, 15]
pick items 2 to 4 from arr
--      it = [12, 13]
pick items 2 to 4 from arr inclusive
--      it = [12, 13, 14]
pick items 2 to 4 from arr exclusive
--      it = [13]

You can use the keywords start or end for start and end, respectively.

pick items from start to 4 from arr
--      it = [10, 11, 12, 13]
pick items from 2 to end from arr
--      it = [12, 13, 14, 15]
pick items from start to end from arr
--      it = [10, 11, 12, 13, 14, 15]

Pick Characters

Syntax

pick characters [...]

pick character [...]

Description

Same as pick items, but for strings, using String.slice.

Pick Match

Syntax

pick match of? regex | flags? from string

Selects the first match for the regex in the string.

set str to "The quick brown fox jumps over the lazy dog."
pick match of "the (\w+)" from str
log it[0] -- "the lazy"
log it[1] -- "lazy"
pick match of "the (\w+)" | i from str
log it[0] -- "The quick"
log it[1] -- "quick"

Pick Matches

Syntax

pick matches of? regex | flags? from string

Returns an iterable of all matches for the regex in the string.

set str to "The quick brown fox jumps over the lazy dog."
pick match of "the (\w+)" | i from str
repeat for match in result index i
  log `${i}:`
  log it[0] -- "The quick"
  log it[1] -- "quick"
end

Output:

0:
The quick
quick
1:
the lazy
lazy