RunMat
GitHub

erase — Remove substring occurrences from text inputs in MATLAB and RunMat.

erase(text, pattern) removes every occurrence of pattern from text. Supported text/pattern forms and expansion behavior match MATLAB semantics.

Syntax

newStr = erase(str, pattern)

Inputs

NameTypeRequiredDefaultDescription
strAnyYesInput text (string/char/cell).
patternAnyYesPattern text list (scalar or array/cell).

Returns

NameTypeDescription
newStrAnyText with substring occurrences removed, preserving input container kind.

Errors

IdentifierWhenMessage
RunMat:erase:InvalidInputFirst argument is not a string array, char array, or cell array of text scalars.erase: first argument must be a string array, character array, or cell array of character vectors
RunMat:erase:PatternTypeSecond argument is not a text scalar/array/cell of text scalars.erase: second argument must be a string array, character array, or cell array of character vectors
RunMat:erase:CellElementCell arrays contain non-text elements or non-row char arrays.erase: cell array elements must be string scalars or character vectors
RunMat:erase:InternalErrorInternal output container construction failed.erase: internal error

How erase works

  • String inputs stay as strings. Missing string scalars (<missing>) propagate unchanged.
  • String arrays preserve their size and orientation. Each element has every supplied pattern removed.
  • Character arrays are processed row by row. Rows shrink as characters are removed and are padded with spaces so the result remains a rectangular char array.
  • Cell arrays must contain string scalars or character vectors. The result is a cell array with the same shape whose elements reflect the removed substrings.
  • The pattern input can be a string scalar, string array, character array, or cell array of character vectors/string scalars. Provide either a scalar pattern or a list; an empty list leaves text unchanged.
  • Pattern values are treated literally—no regular expressions are used. Use replace or the regex builtins for pattern-based removal.

Does RunMat run erase on the GPU?

erase executes on the CPU. When any argument is GPU-resident, RunMat gathers it to host memory before removing substrings. Outputs are returned on the host as well. Providers do not need to implement device kernels for this builtin, and the fusion planner treats it as a sink to avoid keeping text on the GPU.

GPU memory and residency

No. erase automatically gathers GPU inputs and produces host results. You never need to move text to or from the GPU manually for this builtin, and gpuArray inputs are handled transparently.

Examples

Remove a single word from a string scalar

txt = "RunMat accelerates MATLAB code";
clean = erase(txt, "accelerates ")

Expected output:

clean = "RunMat MATLAB code"

Remove multiple substrings from each element of a string array

labels = ["GPU pipeline"; "CPU pipeline"];
result = erase(labels, ["GPU ", "CPU "])

Expected output:

result = 2×1 string
    "pipeline"
    "pipeline"

Erase characters from a character array while preserving padding

chars = char("workspace", "snapshots");
trimmed = erase(chars, "s")

Expected output:

trimmed =

  2×8 char array

    'workpace'
    'naphot '

Remove substrings from a cell array of text

C = {'Kernel Planner', "GPU Fusion"};
out = erase(C, ["Kernel ", "GPU "])

Expected output:

out = 1×2 cell array
    {'Planner'}    {"Fusion"}

Provide an empty pattern list to leave the text unchanged

data = ["alpha", "beta"];
unchanged = erase(data, string.empty)

Expected output:

unchanged = 1×2 string
    "alpha"    "beta"

Remove delimiters before splitting text

path = "runmat/bin:runmat/lib";
clean = erase(path, ":")
parts = split(clean, "runmat/")

Expected output:

clean = "runmat/binrunmat/lib"
parts = 1×3 string
    ""    "bin"    "lib"

Using erase with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how erase changes the result.

Run a small erase example, explain the result, then change one input and compare the output.

FAQ

Can I remove multiple patterns at once?

Yes. Supply pattern as a string array or cell array. Each pattern is removed in order from every element of the input text.

What happens if pattern is empty?

An empty pattern list leaves the input unchanged. Empty string patterns are ignored because removing empty text would have no effect.

Does erase modify the original data?

No. It returns a new value with substrings removed. The input variables remain unchanged.

How are missing string scalars handled?

They propagate unchanged. Calling erase on <missing> returns <missing>, matching MATLAB.

Can erase operate on GPU-resident data?

Indirectly. RunMat automatically gathers GPU values to the host, performs the removal, and returns a host result. No explicit gpuArray calls are required.

How do I remove substrings using patterns or regular expressions?

Use replace for literal substitution or regexprep for regular expressions when you need pattern-based removal rather than literal substring erasure.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how erase is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.