StringFreeQ["string",patt]
yields True if no substring in "string" matches the string expression patt, and yields False otherwise.
StringFreeQ["string",{patt1,patt2,…}]
yields True if no substring matches any of the patti.
StringFreeQ[{"string1","string2",…},patt]
gives a list of the results for each of the "stringi".
StringFreeQ[patt]
represents an operator form of StringFreeQ that can be applied to an expression.
StringFreeQ
StringFreeQ["string",patt]
yields True if no substring in "string" matches the string expression patt, and yields False otherwise.
StringFreeQ["string",{patt1,patt2,…}]
yields True if no substring matches any of the patti.
StringFreeQ[{"string1","string2",…},patt]
gives a list of the results for each of the "stringi".
StringFreeQ[patt]
represents an operator form of StringFreeQ 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.
- StringFreeQ takes the following option:
-
IgnoreCase False whether to turn off case-sensitive matching - Setting the option IgnoreCase->True makes StringFreeQ treat lowercase and uppercase letters as equivalent.
- StringFreeQ[patt][expr] is equivalent to StringFreeQ[expr,patt].
- StringFreeQ[BioSequence["type","seq"],patt] checks 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.
- If the biomolecular sequence operated upon by StringFreeQ is circular, wraparound matches are possible.
Examples
open all close allBasic Examples (3)
Test whether a string contains a substring matching the pattern:
StringFreeQ["abcd", "a"]StringFreeQ["bcde", "b" ~~ __ ~~ "e"]StringFreeQ["bcde", "c" ~~ __ ~~ "t"]Give a list of strings as input:
StringFreeQ[{"a", "b", "ab", "abcd", "bcde"}, "a"]Use the operator form of StringFreeQ:
StringFreeQ["a"]["abcd"]Use the operator form to select strings:
Select[{"CAC1", "CTG1", "ACT1", "CGA1", "CTC1"}, StringFreeQ["G"]]Scope (10)
StringFreeQ["abcade", x_ ~~ x_]StringFreeQ["a1 and a2", DigitCharacter..]StringFreeQ["abcde", RegularExpression["b.*d"]]Mix regular expressions and string patterns:
StringFreeQ["bac 123", RegularExpression["a.*"] ~~ DigitCharacter..]Use pattern matching for dates:
StringFreeQ["31/12/2003", DatePattern[{"Day", "Month", "Year"}]]Test for occurrences of either pattern:
StringFreeQ["abcdabcdcd", {"abc", "cd"}]StringFreeQ["abcdabcdcd", "abc" | "cd"]StringFreeQ automatically threads over lists of strings:
StringFreeQ[{"ability", "listable", "argument"}, "a" ~~ __ ~~ "t" ~~ ___]Check whether a biomolecular sequence is free of a particular substring:
StringFreeQ[BioSequence["DNA", "TCCCATCAATACCAC"], "CTT"]Use a wildcard in the pattern compared against a biomolecular sequence:
StringFreeQ[BioSequence["DNA", "ATGGC"], "AN"]The "N" is a degenerate letter only in biomolecular sequences:
StringFreeQ["ATGGC", "AN"]Check for the absence of literal degenerate letters using Verbatim:
StringFreeQ[BioSequence["DNA", "ATGGC"], "A" ~~ Verbatim["N"]]StringFreeQ[BioSequence["DNA", "ANGGC"], "A" ~~ Verbatim["N"]]Circular sequences support wraparound checks:
StringFreeQ[BioSequence["CircularDNA", "CAGGC"], "CCA"]StringFreeQ[BioSequence["CircularDNA", "CAGGC"], "CCT"]StringFreeQ[BioSequence["CircularDNA", "CAGGC"], "CCN"]Options (2)
IgnoreCase (2)
Use IgnoreCase->True to check for the presence of substrings regardless of case:
StringFreeQ["BACCD", "ac", IgnoreCase -> False]StringFreeQ["BACCD", "ac", IgnoreCase -> True]The operator representation of a case-independent check:
StringFreeQ["ac", IgnoreCase -> True]["BACCD"]Applications (1)
Pick all the lines that contain a substring that matches the pattern:
grep[file_, patt_] := With[{data = Import[file, "Lines"]}, Pick[Transpose[{Range[Length[data]], data}], StringFreeQ[data, patt], False]]Line numbers with corresponding texts that contain "noon" or "day of":
grep["ExampleData/USConstitution.txt", {"noon" , "day of"}]//TableFormProperties & Relations (8)
StringFreeQ threads over lists of strings in the first argument:
StringFreeQ[{"aba", "bcd", "cea"}, "c"]StringFreeQ["string",{patt1,patt2,…}] is equivalent to StringFreeQ["string",Alternatives[patt1,patt2,…]]:
StringFreeQ["cad", {"a", "b"}]StringFreeQ["cad", "a" | "b"]StringContainsQ["string",patt] is equivalent to !StringFreeQ["string",patt]:
StringContainsQ["commit", "co"]StringFreeQ["commit", "co"]Use StringMatchQ to check whether a whole string matches a pattern:
StringMatchQ["commit", "om" ~~ __]StringFreeQ generally returns False when StringMatchQ is True:
StringMatchQ["commit", "co" ~~ __]StringFreeQ["commit", "co" ~~ __]Use StringStartsQ to check whether the start of a string matches a pattern:
StringStartsQ["commit", "om"]StringFreeQ returns False whenever StringStartsQ is True:
StringStartsQ["commit", "co"]StringFreeQ["commit", "co"]Use StringEndsQ to check whether the end of a string matches a pattern:
StringEndsQ["commit", "om"]StringFreeQ returns False whenever StringEndsQ is True:
StringEndsQ["commit", "it"]StringFreeQ["commit", "it"]Get the starting and ending positions where a substring occurs by using StringPosition:
StringFreeQ["agaatcgagttgacacgaccgaaaacgacc", x_ ~~ x_]StringPosition["agaatcgagttgacacgaccgaaaacgacc", x_ ~~ x_]Use StringCases to extract substrings matching a given pattern:
StringFreeQ["abcadcacb", "a" ~~ x_ ~~ "c"]StringCases["abcadcacb", "a" ~~ x_ ~~ "c"]See Also
StringContainsQ StringCount StringCases StringPosition StringMatchQ FreeQ StringStartsQ StringEndsQ StringDelete StringExpression RegularExpression
Function Repository: StringWithinQ
Tech Notes
Related Guides
History
Introduced in 2004 (5.1) | Updated in 2016 (10.4) ▪ 2020 (12.2)
Text
Wolfram Research (2004), StringFreeQ, Wolfram Language function, https://reference.wolfram.com/language/ref/StringFreeQ.html (updated 2020).
CMS
Wolfram Language. 2004. "StringFreeQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringFreeQ.html.
APA
Wolfram Language. (2004). StringFreeQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringFreeQ.html
BibTeX
@misc{reference.wolfram_2026_stringfreeq, author="Wolfram Research", title="{StringFreeQ}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringFreeQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stringfreeq, organization={Wolfram Research}, title={StringFreeQ}, year={2020}, url={https://reference.wolfram.com/language/ref/StringFreeQ.html}, note=[Accessed: 13-June-2026]}