# How to set up patterns when using SequenceSplit

Given a list

lst={0,0,0,0,0,"A1",0,0,0,"B2",0,0,"C3","D4","E5",0,0,0,"F6"}


How to split it as

{{0,0,0,0,0},{"A1",0,0,0},{"B2",0,0},{"C3"},{"D4"},{"E5",0,0,0},{"F6"}}


I want to use SequenceSplit but didn't know how to set up the right pattern.

SequenceSplit[lst, {_String} -> {}]


Thanks!

Split[lst, Not @ StringQ @ #2 &]


{{0, 0, 0, 0, 0}, {"A1", 0, 0, 0}, {"B2", 0, 0}, {"C3"}, {"D4"}, {"E5", 0, 0, 0}, {"F6"}}

SequenceSplit[lst, {s_String, a : Except[_String] ...} :> {s, a}]


{{0, 0, 0, 0, 0}, {"A1", 0, 0, 0}, {"B2", 0, 0}, {"C3"}, {"D4"}, {"E5", 0, 0, 0}, {"F6"}}

• Very nice,Thanks! what do #1 and #2 mean in Split function? – Jerry Jan 13 at 3:49
• @Jerry see Working with Pure Functions and Slot – Mr.Wizard Jan 13 at 3:56
• kglr, do you have something against !? :^) – Mr.Wizard Jan 13 at 3:57
• @Mr.Wizard, thank you. – kglr Jan 13 at 4:01
• @Jerry, in a test function used as the second argument of Split, #1 refers to the first element of a consecutive pair and #2 to the second, See also animation - Split which illustrates how it works for the default test function SameQ. – kglr Jan 13 at 4:04