letterBoundary - Match boundary between letter characters and non-letter characters - MATLAB (original) (raw)
Main Content
Match boundary between letter characters and non-letter characters
Since R2020b
Syntax
Description
[pat](#mw%5F7a12db76-c65c-4252-a5b5-f8df65208eef%5Fsep%5Fmw%5F5d8462f7-c5cb-4493-9ed2-15c426e9be6f) = letterBoundary
creates a pattern that matches the start or end of a run of letter characters. letterBoundary
can be negated using the ~
operator. When negated,~letterBoundary
matches the boundary between any two characters except at the start or end of a run of letters.
[pat](#mw%5F7a12db76-c65c-4252-a5b5-f8df65208eef%5Fsep%5Fmw%5F5d8462f7-c5cb-4493-9ed2-15c426e9be6f) = letterBoundary([type](#mw%5F7a12db76-c65c-4252-a5b5-f8df65208eef%5Fsep%5Fmw%5F3db4ca55-65f2-47cb-817d-7df607c4d0ee))
specifies whether to match at the start or end of a run of letters and numbers.type
can be 'start'
, 'end'
, or'either'
(default).
Examples
Use letterBoundary
to divide a string along boundaries between letters and nonletter characters.
Create a pattern that matches any letter boundaries.
txt = "123 abc .?! def 456"; pat = letterBoundary;
Use replace
to insert "|" characters at the matched boundaries.
ans = "123 |abc| .?! |def| 456"
Use the "start"
and "end"
options for letterBoundary
to match the boundary between letters and nonletter characters.
Create a string that contains several different character types. Create a pattern that matches any characters between a "start"
boundary for letters and an "end"
boundary.
txt = "123 abc .?! def 456"; pat = letterBoundary("start") + wildcardPattern(1,inf) + letterBoundary("end");
Extract the pattern.
boundaries = extract(txt,pat)
boundaries = 2×1 string "abc" "def"
Use the ~
operator to negate letterBoundary
. This matches boundaries between two characters when both are letters or neither are letters.
Create a string that contains several different character types. Create a pattern that matches a negated letterBoundary
.
txt = "123 abc .?!"; pat = ~letterBoundary;
Use replace
to insert "|"
characters to show where ~letterBoundary
matches.
boundaries = replace(txt,pat,"|")
boundaries = "|1|2|3| a|b|c |.|?|!|"
Input Arguments
Boundary type, specified as 'start'
, 'end'
, or 'either'
.
Data Types: char
| string
Extended Capabilities
Version History
Introduced in R2020b