Main Content

lookBehindBoundary

Match boundary following specified pattern

Since R2020b

Description

newpat = lookBehindBoundary(pat) creates a pattern that matches the end of pat. Text matched by pat is not included in the result. lookBehindBoundary can be negated using the ~ operator. When negated, ~lookBehindBoundary matches between any characters that are not at the end of pat.

example

Examples

collapse all

Create a pattern that matches behind "b" or "2".

txt = "abc 123";
pat = lookBehindBoundary("b"|"2");

Use replace to insert "|" characters at the matched boundaries.

replace(txt,pat,"|")
ans = 
"ab|c 12|3"

Use the ~ operator to negate lookBehindBoundary.

Create a pattern that matches digits except for those that directly follow "b" or "2".

txt = "abc 123";
pat = ~lookBehindBoundary("b"|"2");

Use replace to insert "|" characters at the negated boundaries.

replace(txt,pat,"|")
ans = 
"|a|bc| |1|23|"

Input Arguments

collapse all

Input pattern, specified as a pattern, string array, character vector, or cell array of character vectors.

Data Types: char | string | pattern | cell

Output Arguments

collapse all

Output pattern, returned as a pattern or an array of pattern objects.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2020b