Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to rewrite patterns. For example, I'd like to rewrite the pattern


which has FullForm


into just


In other words, I want to strip out the names of patterns. I tried the following

jFoo_Integer /. {Pattern[nym_, Blank[typ_]] :> {nym, typ}}

which does not match or reduce and produces the (IMO bogus) error message

Pattern::patvar: First element in pattern Pattern[nym_,Blank[typ_]] is not a valid pattern name. >>

I also tried

    Pattern[jFoo,Blank[Integer]] /. {Pattern[nym_, Blank[typ_]] :> {nym, typ}}
    Pattern[jFoo,Blank[Integer]] /. {Verbatim[Pattern][nym_, Blank[typ_]] :> {nym, typ}}
    jFoo_Integer /. {Verbatim[Pattern][nym_, Blank[typ_]] :> {nym, typ}}
    jFoo_Integer /. {Verbatim[Pattern][nym_, Blank[typ_]] :> {nym, typ}}

all with exactly the same (failed) results.

Any hints, please & thanks?

share|improve this question
up vote 7 down vote accepted

What you want is probably

jFoo_Integer /. Verbatim[Pattern][nym_, Verbatim[Blank][typ_]] :> {nym, typ}
(* {jFoo, Integer} *)

The usage of Verbatim points it out

Verbatim[expr] represents expr in pattern matching, requiring that expr be matched exactly as it appears, with no substitutions for blanks or other transformations.

share|improve this answer

I'm not sure how do you want to work with it, but those are ways to go:

List @@ (jFoo_Integer)
{jFoo, _Integer}
(jFoo_Integer) /. x_Pattern :> {x[[1]], x[[2]]}
{jFoo, _Integer}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.