lettersPattern

Pattern that matches runs of letters.

Category: Language Fundamentals > Data Types

Syntax

pat = lettersPattern

Matches one or more letters.

pat = lettersPattern(n)

Matches exactly n letters.

pat = lettersPattern(minN, maxN)

Matches between minN and maxN letters.

Description

The pattern is greedy: without limits it takes the longest run of letters it can. Use it with functions that accept patterns, such as extract, split, replace, contains and matches. Digits, spaces and punctuation end a run.

Patterns combine with + for sequence and | for alternatives.

Input arguments

n
Number of letters to match.
minN, maxN
Lower and upper limits for the run length.

Output arguments

pat
A pattern object.

Example

Extracting words

s = 'abc12 d3';
extract(s, lettersPattern)
extract(s, lettersPattern(2))
Output
ans = 2×1 string array

    "abc"
    "d"
ans = "ab"

See also

digitsPattern alphanumericsPattern extract split matches