StringPosition

StringPosition["string","sub"]

gives a list of the starting and ending character positions at which "sub" appears as a substring of "string".

StringPosition["string",patt]

gives all positions at which substrings matching the general string expression patt appear in "string".

StringPosition["string",patt,n]

includes only the first n occurrences of patt.

StringPosition["string",{patt1,patt2,}]

gives positions of all the patti.

StringPosition[{s1,s2,},p]

gives the list of results for each of the si.

StringPosition[patt]

represents an operator form of StringPosition that can be applied to an expression.

Details and Options

Examples

open allclose all

Basic Examples  (3)

Find the starting and ending positions at which "XYZ" occurs in a string:

In[1]:=
Click for copyable input
Out[1]=

Find where any pairs of identical characters occur:

In[1]:=
Click for copyable input
Out[1]=

Use the operator form of StringPosition:

In[1]:=
Click for copyable input
Out[1]=

Scope  (4)

Options  (4)

Applications  (2)

Properties & Relations  (2)

Possible Issues  (1)

See Also

TextPosition  Position  StringCases  StringCount  StringContainsQ  Characters  FindList  ReplaceList  StringExpression  RegularExpression  StringDrop  StringInsert  StringTake  SequenceAlignment

Tutorials

Introduced in 1991
(2.0)
| Updated in 2016
(10.4)