Again, I have a list like this:
list={0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, \
0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, \
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}
I want to search for the pattern: {1,0,0} and mark all the numbers matching this sequence in Red
with the Style
option. I tried to use Cases
to help me out, which does not work. Checked the help a few times, but no idea so far :/
Cases[list, {1,0,0}]
list //. {b__, PatternSequence[1, 0, 0], a__} -> {b, Sequence @@ (Style[#, Red] & /@ {1, 0, 0}), a}
? $\endgroup$a___
andb___
- BlankNullSequence - to include boundary cases for more general situations. $\endgroup$PatternSequence @@ pattern
will strip off theList
head i.e.{}
, of that pattern and make the pattern the argument ofPatternSequence
. Also, make sure to change the replacement to(Style[#, Red] & /@ pattern
as well. $\endgroup$