eraseBetween — Delete text between boundary markers in MATLAB and RunMat.
eraseBetween(text, start, stop) removes text between two boundary markers. Text or numeric positions, expansion rules, and the Boundaries option determine the result.
Syntax
newText = eraseBetween(str, start, end)
newText = eraseBetween(str, start, end, Name, Value, ...)Inputs
str- Type
Any- Required
- Yes
- Description
- Input text scalar/array/cell.
start- Type
Any- Required
- Yes
- Description
- Start boundary marker text or positive integer position(s).
end- Type
Any- Required
- Yes
- Description
- End boundary marker text or positive integer position(s).
Name- Type
StringScalar- Required
- Yes
- Description
- Option name (`Boundaries`).
Value- Type
Any- Required
- Variadic
- Description
- Option value and additional Name/Value pairs.
Returns
newText- Type
Any- Description
- Text with between-boundary content erased, preserving text container semantics.
Errors
RunMat:eraseBetween:InvalidInput- When
- First argument is not a string array, character array, or cell array of text scalars.
- Message
eraseBetween: first argument must be a string array, character array, or cell array of character vectors
RunMat:eraseBetween:BoundaryType- When
- Start/end boundaries are mixed text/numeric domains or use unsupported boundary types.
- Message
eraseBetween: start and end arguments must both be text or both be numeric positions
RunMat:eraseBetween:PositionType- When
- Numeric boundary positions are not positive finite integers.
- Message
eraseBetween: position arguments must be positive integers
Text and boundaries
eraseBetween accepts string scalars, string arrays, character arrays processed row by row, and cell arrays containing string scalars or character vectors. Output keeps the text container kind; string output can expand with boundary arrays, while character and cell outputs cannot expand beyond their text-element shape.
Both boundaries in one call must be text or pattern markers, or both must be numeric positions. Scalar pattern objects are supported; broader pattern-array containers depend on shared pattern-array representation and are not claimed here.
Text boundaries are exclusive by default: the markers remain while the enclosed text is removed. Numeric positions are inclusive by default: the characters at both positions and between them are removed. Boundaries can be changed to inclusive or exclusive with a case-insensitive name-value option.
Missing string text or markers propagate a missing result. If a boundary is not found, the original element is returned unchanged. Numeric positions use exact positive-integer parsing and MATLAB-style one-based indexing; every typed-integer class is accepted as a structural control.
MATLAB-compatible boundary arrays must be scalar or the same size as text. RunMat mode also allows broadcast-compatible boundaries. Character matrices, cells containing string scalars, and resident numeric position arrays are separately gated RunMat extensions.
Placement and effects
The text input and output reside on the host. A resident numeric position control can gather through its owning provider only after RunMat extension admission; strict compatibility rejects it before provider access. Numeric or resident text is invalid and rejects before gathering.
This operation does not run a GPU text kernel or join a fusion plan. It may suspend when gathering an admitted resident control, and it can throw for invalid type, shape, position, or option values. No callback, filesystem, workspace, randomness or time service is involved.
Examples
Remove text between substring markers
txt = "The quick brown fox";
result = eraseBetween(txt, "quick", " fox")Expected output:
result = "The quick fox"Delete enclosed text across a string array
str = ["The quick brown fox jumps"; "over the lazy dog"];
starts = ["quick"; "the"];
ends = [" fox"; " dog"];
trimmed = eraseBetween(str, starts, ends)Expected output:
trimmed = ["The quick fox jumps"; "over the dog"]Erase inclusive numeric positions
name = "Edgar Allen Poe";
short = eraseBetween(name, 6, 11)Expected output:
short = "Edgar Poe"Include text boundary markers in deletion
sentence = "The quick brown fox jumps over the lazy dog";
collapsed = eraseBetween(sentence, " brown", "lazy", "Boundaries", "inclusive")Expected output:
collapsed = "The quick dog"Process padded character rows
chars = char("Server<GPU>", "Engine<CPU>");
trimmed = eraseBetween(chars, "<", ">", "Boundaries", "inclusive")Expected output:
trimmed = ['Server'; 'Engine']Preserve element types in text cells
C = {'alpha<1>', "beta<2>";
'gamma<3>', "delta<4>"};
clean = eraseBetween(C, "<", ">", "Boundaries", "inclusive")Expected output:
clean = {'alpha', "beta"; 'gamma', "delta"}Propagate missing strings
texts = [missing, "Planner<GPU>"];
result = eraseBetween(texts, "<", ">")Expected output:
result = [<missing>, "Planner<>"]Using eraseBetween with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how eraseBetween changes the result.
Run a small eraseBetween example, explain the result, then change one input and compare the output.
FAQ
Which argument types does eraseBetween accept?⌄
Text can be a string scalar or array, character array, or cell of character vectors or string scalars. Both boundaries must be text or pattern markers, or both numeric positions.
What if a boundary is not found?⌄
The original text element is returned unchanged. Missing string values also propagate.
How does Boundaries inclusive work with text markers?⌄
Inclusive mode deletes both matched markers and the enclosed text; exclusive mode keeps the markers.
Can scalar boundaries apply to an array?⌄
Yes. MATLAB-compatible mode also accepts arrays matching text size. General broadcasting is a separately gated RunMat extension.
Are GPU inputs supported?⌄
Text is host-only. In RunMat mode, admitted GPU-resident numeric position controls may gather to host; strict mode rejects that extension before provider access. Numeric or resident text is invalid.
Are numeric positions validated?⌄
Yes. Positions are parsed as exact positive integers with one-based indexing. Every out-of-range detail is not claimed as an independently verified MATLAB guarantee.
Related Strings functions
Transform
append · deblank · erase · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strip · strjoin · strjust · strrep · strsplit · strtrim · upper
Text Analytics
addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · doc2sequence · encode · extractFileText · extractHTMLText · fastTextWordEmbedding · findElement · getAttribute · htmlTree · ind2word · isVocabularyWord · normalizeWords · readWordEmbedding · removeLongWords · removeShortWords · removeStopWords · removeWords · stopWords · tokenDetails · tokenizedDocument · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · wordEncoding · writeWordEmbedding
Core
blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · int2str · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmp · strcmpi · string · string.empty · strings · strlength · strncmp · strncmpi · strtok · unicode2native
Search
contains · endsWith · matches · startsWith · strfind
Pattern
digitsPattern · lettersPattern · pattern · regexpPattern · textBoundary · wildcardPattern
Source you can read
Every RunMat function's source is public. Read exactly how eraseBetween is executed, line by line, in Rust.
- View the source for eraseBetween in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.