gives a list of the starting and ending character positions at which "sub" appears as a substring of "string".
gives all positions at which substrings matching the general string expression patt appear in "string".
includes only the first n occurrences of patt.
gives positions of all the patti.
gives the list of results for each of the si.
Details and Options
- The string expression patt can contain any of the objects specified in the notes for StringExpression.
- With the default option setting Overlaps->True, StringPosition includes substrings that overlap. With the setting Overlaps->False, such substrings are excluded. »
- 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. »
- Setting the option IgnoreCase->True makes StringPosition treat lowercase and uppercase letters as equivalent. »
- StringPosition returns sequence specifications in the form used by StringTake, StringDrop, and StringReplacePart. »
- StringPosition["string",RegularExpression["regex"]] gives positions of substrings matching the specified regular expression.
- StringPosition[patt][expr] is equivalent to StringPosition[expr, patt].
Examplesopen allclose all
Basic Examples (3)
Use the operator form of StringPosition:
Properties & Relations (2)
Possible Issues (1)
Lists of string patterns in StringPosition are sometimes not the same as pattern alternatives: