Main Content

lookAheadBoundary

Match boundary before specified pattern

Since R2020b

Description

example

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

Examples

collapse all

Create a pattern that matches ahead of "b" or "2".

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

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

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

Use the ~ operator to negate lookAheadBoundary.

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

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

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

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

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