Skip to content

strfind

Find one string within another.

k = strfind(str, pattern)

Returns a vector of starting indices of every occurrence of pattern in str. Returns empty if no match. Asymmetric: pattern is searched within str (unlike findstr which searches the shorter within the longer).

strfind('hello world hello', 'hello') % [1 13]
strfind('abcdef', 'xyz') % []
  • findstr — Find one string within another (returns positions of all occurrences).
  • regexp — Match a regular expression against a string.
  • strrep — Replace all occurrences of a substring.