Anchors with SenseTalk's Pattern Language
You can use SenseTalk's pattern language to match patterns within text, as explained in SenseTalk Pattern Language Basics. Sometimes you might want to create matches based on a position within the text rather than on specific text or pattern. Such a match lets you anchor a pattern match or subpattern to the location.
SenseTalk provides several ways of creating anchors within a pattern, each described below:
Defining Basic Anchors
Elements or sub-patterns within a pattern can be anchored at the beginning or end of the text, or the beginning or end of a line or word within the text. For example, the following pattern matches any whole word that begins with c and ends with t, such as cat or coast but doesn't match the same pattern within a word (such as in concatenation):
set wordPattern to <word starting with "c", some characters, "t" at the end of the word>
You can use a number of different syntax forms, to anchor a sub-pattern at the indicated location.
Word Anchor Syntax:
{a | the} word [starting | beginning] {with} pattern -- Beginning of word
{a | the} word {that} [starts | begins] {with} pattern -- Beginning of word
pattern at {the} [start | beginning] of {a | the} word -- Beginning of word
{a | the} word ending {with} pattern -- End of word
{a | the} word {that} ends {with} pattern -- End of word
pattern at {the} [end | ending] of {a | the} word -- End of word
Line Anchor Syntax:
{a | the} line [starting | beginning] {with} pattern -- Beginning of line
{a | the} line {that} [starts | begins] {with} pattern -- Beginning of line
pattern at {the} [start | beginning] of {a | the} line -- Beginning of line
{a | the} line ending {with} pattern -- End of line
{a | the} line {that} ends {with} pattern -- End of line
pattern at {the} [end | ending] of {a | the} line -- End of line
Whole Text Anchor Syntax:
text [starting | beginning] {with} pattern -- Beginning of the text
text {that} [starts | begins] {with} pattern -- Beginning of text
pattern at {the} [start | beginning] of {the} text -- Beginning of text
text ending {with} pattern -- End of the text
text {that} ends {with} pattern -- End of text
pattern at {the} [end | ending] of {the} text -- End of text
Standalone Anchors
You can specify an anchor independently as its own subpattern. Anchors specified like this match at the indicated location, but the match doesn't include any characters. That is, that portion of the match is an empty string.
Standalone Anchors Syntax:
{a | the} word break -- Location at beginning or end of a word
{a | the} [beginning | start | starting] of {a | the} word -- Location at beginning of a word
{a | the} word [beginning | start | starting] -- Location at beginning of a word
{a | an | the} end of {a | the} word -- Location at end of a word
{a | the} word end -- Location at end of a word
{a | the} [beginning | start | starting] of {a | the} line -- Beginning of line
{a | an | the} end of {a | the} line -- End of line
{a | the} line start -- Location at beginning of a line
{a | the} line end -- Location at end of a line
{a | the} [beginning | start | starting] of {a | the} text -- Beginning of text
{a | an | the} end of {a | the} text -- End of text
{a | the} text start -- Location at beginning of the text
{a | the]} text end -- Location at end of the text