StringStartsQ["string",patt]
yields True if the beginning of "string" matches the string expression patt, and yields False otherwise.
StringStartsQ["string",{patt1,patt2,…}]
yields True if the beginning of "string" matches any of the patti.
StringStartsQ[{"string1","string2",…},patt]
gives a list of the results for each of the "stringi".
StringStartsQ[patt]
represents an operator form of StringStartsQ that can be applied to an expression.
StringStartsQ
StringStartsQ["string",patt]
yields True if the beginning of "string" matches the string expression patt, and yields False otherwise.
StringStartsQ["string",{patt1,patt2,…}]
yields True if the beginning of "string" matches any of the patti.
StringStartsQ[{"string1","string2",…},patt]
gives a list of the results for each of the "stringi".
StringStartsQ[patt]
represents an operator form of StringStartsQ that can be applied to an expression.
Details and Options
- The string expression patt can contain any of the objects specified in the notes for StringExpression.
- StringStartsQ takes the following option:
-
IgnoreCase False whether to turn off case-sensitive matching - Setting the option IgnoreCase->True makes StringStartsQ treat lowercase and uppercase letters as equivalent.
- StringStartsQ[patt][expr] is equivalent to StringStartsQ[expr,patt].
- StringStartsQ[BioSequence["type","seq"],patt] checks the start of the string "seq" against patt. In this case, degenerate letters in patt are interpreted as wildcard patterns based on the type of biomolecular sequence. Use Verbatim["patt"] to match degenerate letters literally.
- The documentation for BioSequence lists the degenerate letters supported by each type of biomolecular sequence.
- StringStartsQ has no special behavior for circular biomolecular sequences, but instead interprets the start of the string as the designated start of the sequence.
Examples
open all close allBasic Examples (4)
Check that a string starts with a given prefix:
StringStartsQ["abcd", "a"]StringStartsQ["quickSort", "quick"]StringStartsQ["United States", "United"]Give a list of strings as input:
StringStartsQ[{"int1", "int2", "int3", "float1", "float2", "longint1"}, "int"]Specify a prefix using a string pattern:
StringStartsQ["var1", DigitCharacter ~~ LetterCharacter..]Use the operator form of StringStartsQ:
StringStartsQ["a"]["abcd"]Use the operator form to select strings:
Select[{"CAC1", "CTG1", "ACT1", "CGA1", "CTC1"}, StringStartsQ["C"]]Scope (9)
StringStartsQ["abcade", x_ ~~ x_]StringStartsQ["a1 and a2", x_ ~~ DigitCharacter]StringStartsQ["abcde", RegularExpression["a.*d"]]Mix regular expressions and string patterns:
StringStartsQ["bac 123", RegularExpression["b.*"] ~~ DigitCharacter..]Use pattern matching for dates:
StringStartsQ["31/12/2003 to 01/01/2004", DatePattern[{"Day", "Month", "Year"}]]Test for occurrences of either pattern:
StringStartsQ["abcdabcdcd", {"abc", "cd"}]StringStartsQ["abcdabcdcd", "abc" | "cd"]StringStartsQ automatically threads over lists of strings:
StringStartsQ[{"ability", "listable", "argument"}, "a" ~~ __ ~~ "t" ~~ ___]Check whether a biomolecular sequence starts with a particular substring:
StringStartsQ[BioSequence["DNA", "TGAGCTGTGTTCCCT"], "TGA"]Use a wildcard in the pattern compared against a biomolecular sequence:
StringStartsQ[BioSequence["DNA", "ATGGC"], "AN"]The "N" is a degenerate letter only in biomolecular sequences:
StringStartsQ["ATGGC", "AN"]Check for literal degenerate letters using Verbatim:
StringStartsQ[BioSequence["DNA", "ATGGC"], "A" ~~ Verbatim["N"]]StringStartsQ[BioSequence["DNA", "ANGGC"], "A" ~~ Verbatim["N"]]Options (2)
IgnoreCase (2)
Use IgnoreCaseTrue to check for a leading string regardless of case:
StringStartsQ["Abcd", "a", IgnoreCase -> False]StringStartsQ["Abcd", "a", IgnoreCase -> True]The operator representation of a case-independent check:
StringStartsQ["ba", IgnoreCase -> True]["BACCD"]Properties & Relations (8)
StringStartsQ threads over lists of strings in the first argument:
StringStartsQ[{"aba", "bca", "acd"}, "a"]StringStartsQ["string",{patt1,patt2,…}] is equivalent to StringStartsQ["string",Alternatives[patt1,patt2,…]]:
StringStartsQ["acd", {"a", "b"}]StringStartsQ["acd", "a" | "b"]StringEndsQ checks whether a suffix matches a pattern:
StringEndsQ["commit", "co" ~~ _]StringStartsQ checks whether a prefix matches a pattern:
StringStartsQ["commit", "co" ~~ _]Use StringMatchQ to check whether a whole string matches a pattern:
StringMatchQ["commit", "co"]StringStartsQ checks whether a prefix matches a pattern:
StringStartsQ["commit", "co"]StringStartsQ returns True whenever StringMatchQ is True:
StringMatchQ["commit", "co" ~~ __]StringStartsQ["commit", "co" ~~ __]StringStartsQ["string",patt] is equivalent to StringMatchQ["string",StartOfString~~patt~~___]:
StringStartsQ["commit", "co"]StringMatchQ["commit", StartOfString ~~ "co" ~~ ___]StringStartsQ["string",patt] is equivalent to StringContainsQ["string",StartOfString~~patt]:
StringStartsQ["commit", "co"]StringContainsQ["commit", StartOfString ~~ "co"]Get the starting and ending positions where a prefix occurs by using StringPosition:
StringStartsQ["agaatcgagttgacacgaccgaaaacgacc", x_ ~~ __ ~~ x_]StringPosition["agaatcgagttgacacgaccgaaaacgacc", StartOfString ~~ x_ ~~ __ ~~ x_]Use StringCases to extract prefixes matching a given pattern:
StringStartsQ["abcadcacb", "a" ~~ x__ ~~ "c"]StringCases["abcadcacb", "a" ~~ x__ ~~ "c"]Tech Notes
Related Guides
Text
Wolfram Research (2015), StringStartsQ, Wolfram Language function, https://reference.wolfram.com/language/ref/StringStartsQ.html (updated 2020).
CMS
Wolfram Language. 2015. "StringStartsQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringStartsQ.html.
APA
Wolfram Language. (2015). StringStartsQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringStartsQ.html
BibTeX
@misc{reference.wolfram_2026_stringstartsq, author="Wolfram Research", title="{StringStartsQ}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringStartsQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stringstartsq, organization={Wolfram Research}, title={StringStartsQ}, year={2020}, url={https://reference.wolfram.com/language/ref/StringStartsQ.html}, note=[Accessed: 13-June-2026]}