Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

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 know this is a novice question but I would like a pattern for a list containing zero or more zeros followed by exactly one 1, followed by zero or more zeros. Something like: {0___,1,0___}

But specifying that 0 must be zero.

share|improve this question
I think what you want is .. and ... that is Repeated and RepeatedNull rather than Blank and its friends. – Carlo Aug 8 '14 at 15:19
Yes, thanks to Carlo and Micahal E2. I am using this to build a row reduction method without loops. – John McGee Aug 8 '14 at 16:30
When using patterns, beware of the difference between 1 and 1. or 0 and 0.. Generally, you can also use /; and specify an arbitrary condition in patterns, e.g.row_ /; Count[row, 1] == 1 && Union[row] == {0, 1} (not necessarily the best solution for this particular problem). – Szabolcs Aug 8 '14 at 17:39
up vote 4 down vote accepted

I believe you're looking for RepeatedNull

Count[IdentityMatrix[10], {0 ..., 1, 0 ...}]
(* 10 *)
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.