Skip to content

findstr

Find one string within another (returns positions of all occurrences).

k = findstr(str1, str2)

Searches for the shorter of str1 and str2 within the longer, returning a vector of starting indices for each occurrence. Returns an empty array if no match is found.

Note: MATLAB has deprecated findstr in favor of strfind, which has clearer asymmetric semantics. Prefer strfind for new code.

findstr('the cat', 't') % [1 5]
  • strfind — Find one string within another.
  • regexp — Match a regular expression against a string.