For example, {{1,2,3},{1,2,3,1,2,3,4,5}}with pattern {1,_,3}is transformed to {{Style[1, Red], 2, Style[3, Red]}, {Style[1, Red], 2, Style[3, Red], Style[1, Red], 2, Style[3, Red], 4, 5}}
Also the pattern could be things like {2,_,4,_,6}.
The solutions I can found either require an exact position, or highlight the complete part that matches the pattern (highlights all 1,2,3 in this example).And I have used Select to make sure the list contains this pattern.
How can I achieve this?
Update:
Based on Kuba and Jinxed's answer, I wrote the following code:
color[seq_, pat_] := Module[{i, lst = seq}, i = 1; pattlst = Prepend[Append[ pat /. (Verbatim[_] :> (ToExpression[ "temp$" <> ToString[i++] <> "_"])), last___], first___]; i = 1; target = Prepend[Append[ pat /. (Verbatim[_] :> (ToExpression["temp$" <> ToString[i++]])), last], first]; target = MapAt[Style[#, Red, Bold] &, Position[target, _Integer]][target]; lst //. Evaluate@pattlst :> Evaluate@target] Based on ubpdqn's answer, I wrote:
fun[u_, patt_] := Module[{p = Flatten@Position[Partition[u, Length[patt], 1], patt], rules, res}, rules = {x_, #} :> {Style[x, Red, Bold], #} & /@ Flatten[(Flatten@Position[patt, _Integer] - 1 + #) & /@ p]; res = MapIndexed[{#1, First@#2} &, u] /. rules; res[[;; , 1]]] colorfun[seq_, pat_] := Map[fun[#, pat] &, seq] Not playing well with BenchmarkPlot,I used my OEISSearch Package to generate the test data.

So it seems that ubpdqn's function is faster.

