textBoundary

Pattern that matches the start or end of the text.

Category: Language Fundamentals > Data Types

Syntax

pat = textBoundary

Matches the start or the end of the text.

pat = textBoundary(side)

Matches only the "start" or the "end" of the text (or "either").

Description

textBoundary is a building block for the pattern functions contains, extract, replace, startsWith and others. It is combined with other patterns using +, as in textBoundary("start") + "cat", which only matches cat at the very beginning of the text, not in concat.

Without a text argument it matches both ends, and it differs from lineBoundary, which also recognizes line breaks inside the text.

Input arguments

side
"start", "end" or "either" (default).

Output arguments

pat
A pattern of zero width: it takes up no characters, it only anchors a match to a position.

Example

Anchoring to the text edges

extract("cat concat", textBoundary("start") + "cat")
replace("one two", textBoundary("start"), ">")
replace("one two", textBoundary("end"), "<")
Output
ans = "cat"
ans = ">one two"
ans = "one two<"

See also

lineBoundary letterBoundary whitespaceBoundary replace extract pattern