occurrence, occurrences
-
keyword
-
replace command
-
number of occurrences function
-
Synonyms: instance, instances
-
function — occurrence, every occurrence (of text or pattern)
-
new in 1.81
-
The occurrence and everyOccurrence functions have identical syntax to the offset, range, everyOffset, and everyRange functions. Instead of returning the offset(s) or range(s) of an occurrence, however, these return the actual occurrences of something. These functions can be used to find occurrences of either patterns or strings, but are particularly useful with pattern matching.
put the occurrence of <"(",chars,")"> in "sqrt(42)" —> "(42)"
put every occurrence of <3 digits> in "123456" -> (123,456)
- 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]"