This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Programming / Pattern Matching  /
Alternatives

  • | | ... is a pattern object which represents any of the patterns .
  • Example: _Integer | _Real represents an object with head either Integer or Real.
  • Unless the same set of pattern names appears in all of the , you cannot use these pattern names on the right-hand side of transformation rules for the pattern. Thus, for example, you can use x in a[x_] | b[x_], but you can use neither x nor y in a[x_] | b[y_].
  • See the Mathematica book: Section 2.3.6.
  • See also: Optional.

    Further Examples

    The rule replaces either a or b and nothing else.

    In[1]:=

    Out[1]=