strfind

Searches for all instances of the pattern pat in s. Returns a matrix, R, whose elements are indices of occurrences of pat in s.

Syntax

R = strfind(s, pat)

R = strfind(s, pat,'overlaps','value)

Inputs

s
If type is a cell, all elements must be strings.
Type: string | cell
pat
Pattern to search for in s.
Type: string
'overlaps', value
Optional name-value pair for specifying contents of the output R. Valid options for value are true or false. A value of true will find every instance of pat while a value of false will find only unique instances of pat.
Type: logical

Outputs

R
Type: cell | mat

Examples

String input:
R = strfind('This is a strfind example', 'is')
R = [Matrix] 1 x 2
3  6
Cell array input:
R = strfind({'This', 'is', 'a', 'strfind', 'example'}, 'is')
R =
{
[1,1] 3
[1,2] 1
[1,3] [Matrix] 0 x 0
[1,4] [Matrix] 0 x 0
[1,5] [Matrix] 0 x 0
}
Cell array input with overlapping find:
R=strfind({'This is', 'is', 'a', 'strfind', 'example in help'}, 'is', 'overlaps', true)
R =
{
[1,1] [Matrix] 1 x 2
3  6
[1,2] 1
[1,3] [Matrix] 0 x 0
[1,4] [Matrix] 0 x 0
[1,5] [Matrix] 0 x 0
}
Cell array input with non-overlapping find:
R=strfind({'This is', 'is', 'a', 'strfind', 'example in help'}, 'in', 'overlaps', false)
R =
{
[1,1] [Matrix] 0 x 0
[1,2] [Matrix] 0 x 0
[1,3] [Matrix] 0 x 0
[1,4] 5
[1,5] 9
}