RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • append
    • deblank
    • erase
    • eraseBetween
    • erasePunctuation
    • eraseURLs
    • extractAfter
    • extractBefore
    • extractBetween
    • insertAfter
    • insertBefore
    • join
    • lower
    • pad
    • replace
    • replaceBetween
    • reverse
    • split
    • splitlines
    • strcat
    • strip
    • strjoin
    • strjust
    • strrep
    • strsplit
    • strtrim
    • upper

strrep — Replace non-overlapping substring occurrences in text inputs with MATLAB-compatible container behavior.

strrep(str, old, new) replaces every non-overlapping occurrence of old with new. It supports MATLAB-compatible string, char, and cellstr-style inputs with element-wise replacement semantics.

Syntax

newStr = strrep(str, old, new)

Inputs

NameTypeRequiredDefaultDescription
strAnyYes—Input text (string/char/cell).
oldAnyYes—Pattern text scalar (string or char row).
newAnyYes—Replacement text scalar matching old's data type family.

Returns

NameTypeDescription
newStrAnyText with pattern occurrences replaced, preserving input container kind.

Errors

IdentifierWhenMessage
RunMat:strrep:InvalidInputFirst argument is not a string array, char array, or cell array of text scalars.strrep: first argument must be a string array, character array, or cell array of character vectors
RunMat:strrep:PatternTypeold/new arguments are not string scalars or character vectors.strrep: old and new must be string scalars or character vectors
RunMat:strrep:PatternMismatchold and new are different text data families (string vs char).strrep: old and new must be the same data type
RunMat:strrep:CellElementCell input contains non-text elements or non-row char arrays.strrep: cell array elements must be string scalars or character vectors
RunMat:strrep:InternalErrorInternal output container construction failed.strrep: internal error

How strrep works

  • String scalars remain strings. Missing string values (<missing>) propagate unchanged.
  • String arrays are processed element-wise while preserving their full shape and orientation.
  • Character arrays are handled row by row. Rows expand or shrink as needed and are padded with spaces so the result stays a rectangular char array, just like MATLAB.
  • Cell arrays must contain character vectors or string scalars. The result is a cell array of identical size where each element has had the replacement applied.
  • The old and new arguments must be string scalars or character vectors of the same data type.
  • old can be empty. In that case, strrep inserts new before the first character, between existing characters, and after the final character.
  • Integer values in any of the three text roles are rejected rather than treated as character codes or formatted numbers.

Does RunMat run strrep on the GPU?

strrep computes replacements on host text and returns a host text container of the corresponding kind. Numeric resident values reject before provider access rather than being gathered and implicitly converted to text.

GPU memory and residency

No. strrep accepts host text and returns host text. Provider-resident numeric values are unsupported and reject before access.

Examples

Replacing a word inside a string scalar

txt = "RunMat turbo mode";
result = strrep(txt, "turbo", "accelerate")

Expected output:

result = "RunMat accelerate mode"

Updating every element of a string array

labels = ["GPU planner", "CPU planner"];
updated = strrep(labels, "planner", "pipeline")

Expected output:

updated = 2×1 string
    "GPU pipeline"
    "CPU pipeline"

Preserving rectangular shape in character arrays

chars = char("alpha", "beta ");
out = strrep(chars, "a", "A")

Expected output:

out =

  2×5 char array

    'AlphA'
    'betA '

Applying replacements inside a cell array of character vectors

C = {'Kernel Fusion', 'GPU Planner'};
renamed = strrep(C, ' ', '_')

Expected output:

renamed = 1×2 cell array
    {'Kernel_Fusion'}    {'GPU_Planner'}

Inserting text with an empty search pattern

stub = "abc";
expanded = strrep(stub, "", "-")

Expected output:

expanded = "-a-b-c-"

Leaving missing string values untouched

vals = ["RunMat", "<missing>", "Accelerate"];
out = strrep(vals, "RunMat", "RUNMAT")

Expected output:

out = 1×3 string
    "RUNMAT"    <missing>    "Accelerate"

Replacing substrings gathered from GPU inputs

g = gpuArray("native-code");
host = strrep(g, "code", "path")

Expected output:

host = "native-path"

Using strrep with coding agents

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

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

FAQ

Which input types does strrep accept?⌄

String scalars, string arrays, character vectors, character arrays, and cell arrays of character vectors. The old and new arguments must be string scalars or character vectors of the same data type.

Does strrep support multiple search terms at once?⌄

No. Use the newer replace builtin if you need to substitute several search terms in a single call.

How does strrep handle missing strings?⌄

Missing string scalars remain <missing> and are returned unchanged, even when the search pattern matches ordinary text.

Will rows of a character array stay aligned?⌄

Yes. Each row is replaced individually, then padded with spaces so that the overall array stays rectangular, matching MATLAB exactly.

What happens when old is empty?⌄

RunMat mirrors MATLAB: new is inserted before the first character, between every existing character, and after the last character.

Does strrep run on the GPU?⌄

No GPU text representation is supported. Numeric GPU values are not text and reject before provider access; convert supported host data to strings explicitly before calling strrep.

Can I mix strings and character vectors for old and new?⌄

No. MATLAB requires old and new to share the same data type. RunMat enforces the same rule and raises a descriptive error when they differ.

How do I replace text stored inside cell arrays?⌄

strrep traverses the cell array, applying the replacement to each character vector or string scalar element and returning a cell array of the same shape.

Related Strings functions

Transform

append · deblank · erase · eraseBetween · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strip · strjoin · strjust · 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

Regex

regexp · regexpi · regexprep

Open-source implementation

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

  • View the source for strrep in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

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.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How strrep works
  • Does RunMat run strrep on the GPU?
  • GPU memory and residency
  • Examples
  • Replacing a word inside a string scalar
  • Updating every element of a string array
  • Preserving rectangular shape in character arrays
  • Applying replacements inside a cell array of character vectors
  • Inserting text with an empty search pattern
  • Leaving missing string values untouched
  • Replacing substrings gathered from GPU inputs
  • Using strrep with coding agents
  • FAQ
  • Related Strings functions
  • Transform
  • Text Analytics
  • Core
  • Search
  • Pattern
  • Regex
  • Open-source implementation
  • About RunMat