alphanumericBoundary - Match boundary between alphanumeric and non-alphanumeric characters - MATLAB (original) (raw)

Main Content

Match boundary between alphanumeric and non-alphanumeric characters

Since R2020b

Syntax

Description

[pat](#mw%5F1d7aadb7-e5a9-47c9-bd27-6b5ceb0b56b9%5Fsep%5Fmw%5F5d8462f7-c5cb-4493-9ed2-15c426e9be6f) = alphanumericBoundary creates a pattern that matches the start or end of a run of letters and numbers.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.

example

[pat](#mw%5F1d7aadb7-e5a9-47c9-bd27-6b5ceb0b56b9%5Fsep%5Fmw%5F5d8462f7-c5cb-4493-9ed2-15c426e9be6f) = alphanumericBoundary([type](#mw%5F1d7aadb7-e5a9-47c9-bd27-6b5ceb0b56b9%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).

example

Examples

collapse all

Use alphanumericBoundary to divide text along boundaries between letters and digits and non-alphanumeric characters.

txt = "123abc .?! def456"; pat = alphanumericBoundary;

Use 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|"

Use the "start" and "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 "end" boundary.

txt = "123 abc .?! def 456"; pat = alphanumericBoundary("start") + wildcardPattern(1,inf) + alphanumericBoundary("end");

Extract the pattern.

boundaries = extract(txt,pat)

boundaries = 4×1 string "123" "abc" "def" "456"

Use the ~ 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 alphanumericBoundary.

txt = "123 abc .?!"; pat = ~alphanumericBoundary;

Use replace to insert "|" characters to show where ~alphanumericBoundary matches.

boundaries = replace(txt,pat,"|")

boundaries = "1|2|3 a|b|c |.|?|!|"

Input Arguments

collapse all

Boundary type, specified as 'start', 'end', or 'either'.

Data Types: char | string

Extended Capabilities

Version History

Introduced in R2020b