Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Português - 日本語 - Русский

Please note that the recommended version of Scilab is 6.0.1. This page might be outdated.
See the recommended documentation of this function

Aide de Scilab >> Chaînes de caractères > strindex


search position of a character string in an other string

Calling Sequence

ind = strindex(haystack, needle, [flag])
[ind, which] = strindex(haystack, needle, [flag])



a character string. The string where to search occurrences of needle.


a character string or character string vector. The string(s) to search in haystack.


a vector of indexes.


a vector of indexes.


a string ("r" for regular expression).


strindex searches indexes where needle(i) is found in haystack.

For each k it exist an i such that part(haystack,ind(k)+(0:length(needle(i))-1)) is the same string than needle(i). If which argument is required it contains these i. When using the third parameter "r", the needle should be a string of regular expression. And then strindex is going to match it with haystack according to the regular express rules.

strindex without regular expression argument is based on Knuth-Morris-Pratt algorithm.

This algorithm is more powerful than that used in Scilab 4.x. In some special case, result can be different.


// Scilab 5.x


w = 1. 1. 2. k = 1. 2. 2.

// Scilab 4.x


w = 1. 1. k = 1. 2.

The rules of regular expression are similar to Perl language. For a quick start, see For a more in-depth tutorial on, see and for the reference page, see


k=strindex('2' ,'/2(]*)?$\1/' ,'r')

See Also

  • string — conversion en chaîne de caractères
  • strings — Scilab Object, character strings
  • regexp — find a substring that matches the regular expression string
  • strsubst — substitute a character string by another in a character string
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 02 13:54:34 CEST 2014