string.extractBetween
string: newstr = extractBetween (str, startPat, endPat)
string: newstr = extractBetween (str, startPos, endPos)
string: newstr = extractBetween (…, "Boundaries", bounds)
Extract the substrings between start and end boundaries.
newstr = extractBetween (str, startPat,
endPat) returns the text that occurs between the substrings
startPat and endPat in each element of str.
startPat and endPat can be string arrays, character vectors,
or cell arrays of character vectors. Within each element the boundary
pairs are matched from left to right and do not overlap, so an element
may yield several substrings; these run along the second dimension, and
every element of str must yield the same number of matches. For a
string scalar with n matches, newstr is 1xn;
for a non-scalar str, newstr has one row per element (taken
in column-major order) and one column per match. Elements with no match,
including missing values, are treated as having zero matches.
newstr = extractBetween (str, startPos,
endPos) returns the substring between the character positions
startPos and endPos, inclusive of the characters at those
positions. This syntax extracts a single substring per element, so
newstr has the same size as str.
newstr = extractBetween (…, specifies whether the boundaries are included in or
excluded from the extracted text. bounds can be either
"Boundaries",
bounds)"inclusive" or "exclusive". When boundaries are given
as substrings, the default is "exclusive" and the boundary
substrings are not included; when given as positions, the default is
"inclusive" and the characters at those positions are included.
startPat/endPat and startPos/endPos must either be scalars, applied to every element of str, or be of the same size as str. Missing values in str are preserved.
Source Code: string
extractBetween returns the text lying between two delimiters.
s = string ({'[abc]'; '[hello]'})
s =
2x1 string array
"[abc]"
"[hello]"
extractBetween (s, '[', ']')
ans =
2x1 string array
"abc"
"hello"