This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

StringPosition

StringPosition
gives a list of the starting and ending character positions at which appears as a substring of .
StringPosition
gives all positions at which substrings matching the general string expression patt appear in .
StringPosition
includes only the first n occurrences of patt.
StringPosition
gives positions of all the .
StringPosition
gives the list of results for each of the .
  • The string expression patt can contain any of the objects specified in the notes for StringExpression.
  • With Overlaps->All, multiple substrings that match the same string expression are all included. With Overlaps->True, only the first such matching substring at a given position is included. »
Find the starting and ending positions at which "XYZ" occurs in a string:
Find where any pairs of identical characters occur:
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]=
StringPosition gives substring positions in the form used by functions like StringTake:
Find the position of the first occurrence of "XYZ":
StringPosition by default includes overlaps:
Use Overlaps->False to exclude overlaps:
Treat "a" and "A" as the same:
Treat "a" and "A" as different:
Find successive identical characters independent of case:
StringPosition by default includes overlaps:
By default, StringPosition only includes one substring starting at any given position:
With Overlaps->All, it includes all substrings:
Find positions of pairs of identical letters in a concatenation sequence:
Find an analogous curve for triples:
Find the positions of the word "president" in the U.S. Constitution:
Use StringTake to extract substrings found by StringPosition:
StringCases by default excludes overlaps:
Use StringReplacePart to replace at positions found by StringPosition:
Lists of string patterns in StringPosition are sometimes not the same as pattern alternatives:
New in 2 | Last modified in 5.1