asManyOfPattern - Match pattern as many times as possible - MATLAB (original) (raw)
Match pattern as many times as possible
Since R2020b
Syntax
Description
[newpat](#mw%5F1e5344cd-2d1a-4411-9984-ec9262096d7e%5Fsep%5Fmw%5F2527cdca-90c8-43b1-8ea8-8fa52700322c) = asManyOfPattern([pat](#mw%5F1e5344cd-2d1a-4411-9984-ec9262096d7e%5Fsep%5Fmw%5F619a0af2-3091-404f-9c61-e268bcf7fbcb))
creates a pattern that matches as many consecutive instances of pat
as possible, including zero times.
[newpat](#mw%5F1e5344cd-2d1a-4411-9984-ec9262096d7e%5Fsep%5Fmw%5F2527cdca-90c8-43b1-8ea8-8fa52700322c) = asManyOfPattern([pat](#mw%5F1e5344cd-2d1a-4411-9984-ec9262096d7e%5Fsep%5Fmw%5F619a0af2-3091-404f-9c61-e268bcf7fbcb),[minPattern](#mw%5Fefff2e33-fe76-44cf-9913-946fa59f69bf))
specifies a minimum number of consecutive instances to match withminPattern
.
[newpat](#mw%5F1e5344cd-2d1a-4411-9984-ec9262096d7e%5Fsep%5Fmw%5F2527cdca-90c8-43b1-8ea8-8fa52700322c) = asManyOfPattern([pat](#mw%5F1e5344cd-2d1a-4411-9984-ec9262096d7e%5Fsep%5Fmw%5F619a0af2-3091-404f-9c61-e268bcf7fbcb),[minPattern](#mw%5Fefff2e33-fe76-44cf-9913-946fa59f69bf),[maxPattern](#mw%5Fec872f3e-0a58-4cbe-88f7-933415f7eb6f))
specifies a minimum and a maximum number of consecutive instances to match.asManyOfPattern
matches at least minPattern
consecutive instances, but no more than maxPattern
.
Examples
Use asManyOfPattern
to match as many individual letters as possible between two instances of "b"
.
Create txt
as a string. Create a pattern, pat
, that matches as many of the letters "a"
or "b"
as possible between two instances of the character "b"
.
txt = "bb bab babab babaaabab"; pat = "b" + asManyOfPattern("a"|"b") + "b";
Use replace
to replace text matched by pat
with the character "*"
.
Use asManyOfPattern
to match as many individual letters as possible between two instances of "b"
, but require at least three letters.
Create txt
as a string. Create a pattern, pat
, that matches as many of the letters "a"
or "b"
as possible between two instances of the character "b"
but specify that there must be a minimum of three matched letters.
txt = "bb bab babab babaaabab"; pat = "b" + asManyOfPattern("a"|"b",3) + "b";
Use replace
to replace text matched by pat
with the character "*"
.
Use asManyOfPattern
to match as many individual letters as possible between two instances of "b"
, but require at least three and no more than four letters.
Create txt
as a string. Create a pattern, pat
, that matches as many of the letters "a"
or "b"
as possible between two instances of the character "b"
, but specify that there must be a minimum of three and a maximum of four matched letters.
txt = "bb bab babab babaaabab"; pat = "b" + asManyOfPattern("a"|"b",3,4) + "b";
Use replace
to replace text matched by pat
with the character "*"
.
Input Arguments
Input pattern, specified as a pattern, string array, character vector, or cell array of character vectors.
Data Types: char
| string
| pattern
| cell
Minimum number of consecutive instances to match, specified as a nonnegative integer scalar.
Data Types: single
| double
Maximum number of consecutive instances to match, specified as a nonnegative integer scalar.
Data Types: single
| double
Output Arguments
Output pattern, returned as a pattern or an array of pattern objects.
Extended Capabilities
Version History
Introduced in R2020b