StringIndices
Returns a list with the positions of all occurrences of a given substring in a string.
Syntax
-
StringIndices(s, x[, f[, δ]])-
sis the string to be searched -
xis the substring to search for -
fis a string -
δis a positive integer
-
Description
If s and x are strings, then StringIndices returns the list with the positions of all occurrences of x in s, subject to any additional restrictions imposed by the remaining arguments. The list is sorted.
f specifies flags for the algorithm. It is a string that can contain zero or more of the following characters:
-
i: MakesStringIndicessearch forxin a case-insensitive manner. -
w: MakesStringIndicesonly considerxto be a substring ofsifxis found as a full word ins.
If omitted, f defaults to "" (no options).
Finally, if δ is specified, StringIndices will begin searching s for x at character index δ in s (the first character having index 1).
Examples
Alice ≔ ExampleData("Alice in Wonderland");
StringIndices(Alice, "rabbit", "i") \ 10
118 696 850 1069 1260 1455 1605 5390 5675 13749 ⋮