lineBoundary

Pattern that matches the start or end of a line.

Category: Language Fundamentals > Data Types

Syntax

pat = lineBoundary

Matches the start or the end of a line.

pat = lineBoundary('start')

Matches only at the start of a line.

pat = lineBoundary('end')

Matches only at the end of a line.

Description

Lines are separated by newline characters. The boundary also matches at the very beginning and end of the text. Like other boundaries it has zero width, so it anchors a neighboring pattern: lineBoundary('start') + lettersPattern takes the letters at the beginning of each line.

Compare with textBoundary, which matches only at the ends of the whole text.

Input arguments

'start' | 'end'
Optional. Restricts the match to line starts or line ends.

Output arguments

pat
A pattern object. It consumes no characters.

Example

First word of each line

s = sprintf('one two\nthree four');
extract(s, lineBoundary('start') + lettersPattern)
Output
ans = 2×1 string array

    "one"
    "three"

See also

textBoundary letterBoundary pattern extract splitlines