letterBoundary

Pattern that matches the edge between a letter and a non-letter.

Category: Language Fundamentals > Data Types

Syntax

pat = letterBoundary

Returns a pattern matching a zero-width position at the start or end of a run of letters.

pat = letterBoundary('start')

Matches only where a letter run begins.

pat = letterBoundary('end')

Matches only where a letter run ends.

Description

A boundary pattern matches a position, not text, so it is combined with other patterns using + to anchor them. letterBoundary + 'cat' finds cat only at the beginning of a word, and 'cat' + letterBoundary only at its end. Putting the boundary on both sides asks for the whole word.

Input arguments

'start' | 'end'
Optional. Restricts the boundary to the beginning or the end of a run of letters.

Output arguments

pat
A pattern object. It consumes no characters.

Example

Whole-word matching

str = 'cat concat cat!';
extract(str, letterBoundary + 'cat' + letterBoundary)
Output
ans = 2×1 string array

    "cat"
    "cat"

See also

lettersPattern lineBoundary pattern extract contains