I am beginning to put together a javascript that will enable me to place words in the document dictionary and am struggling to understand the relationship between InDesign Object Word and the words method and how else I might find only the words within a text object at the selection level.
Select "grapes" run
app.selection.constructor.name returns "Word"
app.selection.contents returns "grapes"
Select "grapes,"
app.selection.constructor.name returns "Text"
app.selection.words[1].contents returns "grapes," not grapes.
Any punctuation that is attached to a word in a selection other than whitespace appears to be considered to be part of the word in the words collection.
Short of resorting to regex, is there away to return only the word?
TIA
@Trevor
Many thanks the link explained what I thought was happening. I was going to explore grep, but thought I might be missing something and there was some DOM element I had missed. Thanks also for the script snippet you have done my work for me!
InDesign must do some sort of grep internally because if you highlight a word plus punctuation and attempt to add it to the dictionary, it strips off the punctuation.
North America
Europe, Middle East and Africa
Asia Pacific