sym:obj or Pattern[sym,obj]
represents the pattern object obj, assigned the name sym.
Pattern 
sym:obj or Pattern[sym,obj]
represents the pattern object obj, assigned the name sym.
Details
- The name sym must be a symbol.
- The object obj can be any pattern object.
- When a transformation rule is used, any occurrence of s on the right‐hand side is replaced by whatever expression it matched on the left‐hand side.
- The operator : has a comparatively low precedence. The expression x:_+_ is thus interpreted as x:(_+_), not (x:_)+_.
- The form s_ is equivalent to s:_. Similarly, s_h is equivalent to s:_h, s__ to s:__, and so on. »
Examples
open all close allBasic Examples (1)
Scope (1)
Use Pattern in any pattern-matching function including ReplaceAll:
{x} /. n : (x | y) :> n + 2Cases[{x, y, z}, n : (x | y) :> n + 2]And MatchQ:
MatchQ[x, n : (x | y)]Properties & Relations (1)
The forms s_ and s:_ are equivalent:
{FullForm[s_], FullForm[s : _]}This extends to forms with a specified head:
{FullForm[s_h], FullForm[s : _h]}As well as forms involving BlankSequence and BlankNullSequence:
{FullForm[s__], FullForm[s : ___]}Possible Issues (1)
The input s:v is a form of Pattern only if s is a symbol:
FullForm[s : v]If s is a special input form for Blank[…] or Pattern[sym,Blank[…]], then s:v is Optional[s,v]:
{FullForm[_ : v], FullForm[s_ : v]}Forms involving BlankSequence[…] and BlankNullSequence[…] are similar:
{FullForm[__ : v], FullForm[s___ : v]}If s is any other expression, the form is not valid input:
ToExpression["f[]:v"]See Also
Blank Optional Alternatives BlankSequence BlankNullSequence PatternTest Condition StringExpression
Function Repository: PatternBindings PatternSort
Related Guides
Related Workflows
- Write a Function That Can Return Unevaluated
Related Links
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), Pattern, Wolfram Language function, https://reference.wolfram.com/language/ref/Pattern.html.
CMS
Wolfram Language. 1988. "Pattern." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Pattern.html.
APA
Wolfram Language. (1988). Pattern. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Pattern.html
BibTeX
@misc{reference.wolfram_2026_pattern, author="Wolfram Research", title="{Pattern}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Pattern.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_pattern, organization={Wolfram Research}, title={Pattern}, year={1988}, url={https://reference.wolfram.com/language/ref/Pattern.html}, note=[Accessed: 12-June-2026]}