Match boundary between letter characters and nonletter characters
creates a pattern that
matches the start or end of a run of letter characters.
pat = 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.
Match Boundaries of Letters
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;
replace to insert "|" characters at the matched boundaries.
ans = "123 |abc| .?! |def| 456"
Match Start and End Boundaries of Letters
"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
txt = "123 abc .?! def 456"; pat = letterBoundary("start") + wildcardPattern(1,inf) + letterBoundary("end");
Extract the pattern.
boundaries = extract(txt,pat)
boundaries = 2x1 string "abc" "def"
Negating Boundaries of Letters
~ 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
txt = "123 abc .?!"; pat = ~letterBoundary;
replace to insert
"|" characters to show where ~
boundaries = replace(txt,pat,"|")
boundaries = "|1|2|3| a|b|c |.|?|!|"
type — Boundary type
'either' (default) |
Boundary type, specified as