Match boundary between digit characters and nondigit characters
creates a pattern that
matches the start or end of a run of digit characters.
pat = digitBoundary
be negated using the
~ operator. When negated,
~digitBoundary matches the boundary between any two characters except
at the start or end of a run of digits.
Match Boundaries of Digit Characters
digitBoundary to divide a string along boundaries between digits and nondigit characters.
Create a pattern that matches any digit boundaries.
txt = "123 abc .?! def 456"; pat = digitBoundary;
replace to insert "|" characters at the matched boundaries.
ans = "|123| abc .?! def |456|"
Match Start and End Boundaries of Digits
"end" options for
digitBoundary to match the boundary between digits and nondigit characters.
Create a string that contains several different character types. Create a pattern that matches any characters between the
"start" boundary for digits and an
txt = "123 abc .?! def 456"; pat = digitBoundary("start") + wildcardPattern(1,inf) + digitBoundary("end");
Extract the pattern.
boundaries = extract(txt,pat)
boundaries = 2x1 string "123" "456"
Negating Boundaries of Digits
~ operator to negate
digitBoundary. This matches the boundary between two characters when both are digit characters or neither is a digit character.
Create a string that contains several different character types. Create a pattern that matches a negated
txt = "123 abc .?!"; pat = ~digitBoundary;
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