Match boundary between alphanumeric and non-alphanumeric characters
creates a pattern
that matches the start or end of a run of letters and numbers.
pat = alphanumericBoundary
alphanumericBoundary can be negated using the
operator. When negated,
~alphanumericBoundary matches the boundary
between any two characters except at the start or end of a run of alphanumerics.
Match Boundaries of Letters and Digits
alphanumericBoundary to divide text along boundaries between letters and digits and non-alphanumeric characters.
txt = "123abc .?! def456"; pat = alphanumericBoundary;
replace to insert "|" characters at the matched boundaries. This operation shows where these boundaries are in the text that contains a variety of character types.
ans = "|123abc| .?! |def456|"
Match Start and End Boundaries of Letters and Digits
"end" options for
alphanumericBoundary to match the boundary between letters and digits and non-alphanumeric characters.
Create a string that contains several different character types. Create a pattern that matches any characters between a
"start" boundary of letters and digits and an
txt = "123 abc .?! def 456"; pat = alphanumericBoundary("start") + wildcardPattern(1,inf) + alphanumericBoundary("end");
Extract the pattern.
boundaries = extract(txt,pat)
boundaries = 4x1 string "123" "abc" "def" "456"
Negating Boundaries of Letters and Digits
~ operator to negate
alphanumericBoundary. This pattern matches the boundary between two characters when both are alphanumeric characters or neither character is alphanumeric.
Create a string that contains several different character types. Create a pattern that matches a negated
txt = "123 abc .?!"; pat = ~alphanumericBoundary;
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
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
Introduced in R2020b