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
    • contains
    • endsWith
    • matches
    • startsWith
    • strfind

contains — Test whether text inputs contain patterns in MATLAB and RunMat.

contains(str, pattern) returns logical results indicating whether each element of str contains the corresponding text in pattern. It supports string arrays, character arrays, and cell text inputs with implicit expansion behavior matching MATLAB and RunMat.

Syntax

tf = contains(str, pat)
tf = contains(str, pat, ignoreCase)
tf = contains(str, pat, "IgnoreCase", value)

Inputs

NameTypeRequiredDefaultDescription
strAnyYes—Text input (string/char/cell/string array).
patAnyYes—Pattern text (string/char/cell/string array).
ignoreCaseAnyYesfalseLogical flag controlling case-sensitive matching.
nameStringScalarYes"IgnoreCase"Option name (`"IgnoreCase"`).
valueAnyYes—Option value for `"IgnoreCase"`.

Returns

NameTypeDescription
tfLogicalArrayLogical result indicating whether each text element contains the pattern.

Errors

IdentifierWhenMessage
RunMat:contains:InvalidInputText or pattern input is not a supported text container.contains: text and pattern inputs must be text values
RunMat:contains:InvalidOptionIgnoreCase option arguments are invalid or malformed.contains: invalid option arguments
RunMat:contains:ShapeMismatchText and pattern inputs are not broadcast-compatible.contains: input sizes are not broadcast-compatible
RunMat:contains:InternalErrorInternal logical result assembly failed.contains: internal error

How contains works

  • Accepts text inputs as string scalars/arrays, character scalars/arrays, or cell arrays of character vectors.
  • Accepts patterns in the same formats. Either input may be scalar; when sizes differ MATLAB-style implicit expansion applies.
  • Missing string scalars (<missing>) never match any pattern.
  • Empty pattern values ("" or '') always match non-missing text elements.
  • The optional 'IgnoreCase', true|false name-value pair controls case sensitivity (default is case-sensitive).
  • Returns a logical scalar when the broadcasted size is one element, otherwise returns a logical array with the broadcasted shape.

Does RunMat run contains on the GPU?

contains performs host-side text comparisons and registers no provider hook. Resident numeric inputs reject before provider access because they are not text values.

GPU memory and residency

contains executes on host text values. RunMat currently has no GPU-resident string representation, so a numeric gpuArray is rejected as nontext before any provider download.

Examples

Check if a string contains a substring

tf = contains("RunMat Accelerate", "Accelerate")

Expected output:

tf = logical
   1

Perform a case-insensitive search

tf = contains("RunMat", "run", 'IgnoreCase', true)

Expected output:

tf = logical
   1

Apply a scalar pattern to every element of a string array

labels = ["alpha" "beta" "gamma"];
tf = contains(labels, "a")

Expected output:

tf = 1×3 logical array
   1   1   1

Match element-wise patterns with implicit expansion

names = ["hydrogen"; "helium"; "lithium"];
patterns = ["gen"; "ium"; "iron"];
tf = contains(names, patterns)

Expected output:

tf = 3×1 logical array
   1
   1
   0

Search a cell array of character vectors

C = {'Mercury', 'Venus', 'Mars'};
tf = contains(C, 'us')

Expected output:

tf = 1×3 logical array
   0   1   0

Provide multiple patterns as a column vector

tf = contains("saturn", ['s'; 'n'; 'x'])

Expected output:

tf = 3×1 logical array
   1
   1
   0

Handle empty and missing text values

texts = ["", "<missing>"];
tf = contains(texts, "")

Expected output:

tf = 1×2 logical array
   1   0

Using contains with coding agents

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

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

FAQ

What types can I pass to contains?⌄

Use string scalars/arrays, character vectors/arrays, or cell arrays of character vectors for both the text and the pattern. Mixed combinations are accepted, and RunMat performs MATLAB-style implicit expansion when the array sizes differ.

How do I ignore letter case?⌄

Specify 'IgnoreCase', true after the pattern argument. The option name is case-insensitive and the default is false. Positional, numeric, and textual flag conveniences are available only in RunMat compatibility mode.

What happens with empty patterns?⌄

Empty patterns ("" or '') always match non-missing text elements. When the text element is missing (<missing>), the result is false.

Can I search for multiple patterns at once?⌄

Yes. Provide pattern as a string array, character array, or cell array of character vectors. RunMat applies implicit expansion so that scalar inputs expand across the other argument automatically.

How are missing strings treated?⌄

Missing string scalars (displayed as <missing>) never match any pattern and produce false in the result. Use ismissing if you need to separate missing values before calling contains.

Does contains run on the GPU?⌄

No. The builtin executes on the CPU, and RunMat has no GPU-resident text representation. Numeric gpuArray values reject as nontext before provider access.

Does contains preserve the input shape?⌄

Yes. The output is a logical array whose shape is the implicit-expansion result of the input shapes. When the broadcasted shape has exactly one element, the builtin returns a logical scalar.

Related Strings functions

Search

endsWith · matches · startsWith · strfind

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

Transform

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

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

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 contains is executed, line by line, in Rust.

  • View the source for contains 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 contains works
  • Does RunMat run contains on the GPU?
  • GPU memory and residency
  • Examples
  • Check if a string contains a substring
  • Perform a case-insensitive search
  • Apply a scalar pattern to every element of a string array
  • Match element-wise patterns with implicit expansion
  • Search a cell array of character vectors
  • Provide multiple patterns as a column vector
  • Handle empty and missing text values
  • Using contains with coding agents
  • FAQ
  • Related Strings functions
  • Search
  • Text Analytics
  • Transform
  • Core
  • Pattern
  • Regex
  • Open-source implementation
  • About RunMat