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 OptionsDetails and Options

ExamplesExamplesopen allclose all

Basic Examples  (3)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]=
Introduced in 1991
(2.0)
| Updated in 2016
(10.4)