joining adjacent elements by rule
StringJoin /@ SplitBy[lis, DigitQ]
yields:
{"a", "1", "cefg", "2"}
You can also use SequenceReplace
:
ClearAll[sR]
sR = SequenceReplace[{p : __?(StringMatchQ[LetterCharacter ..])} :> StringJoin[p]]
or, a variation on ubpdqn's approach, using Split
:
ClearAll[splitAndJoin]
splitAndJoin = StringJoin /@ Split[#, Nor @@ (DigitQ /@ {##}) &] &
Examples:
lis1 = {"a", "1", "c", "ef", "g", "2"};
lis2 = {"a", "1", "c", "ef", "g", "2", "345", "A", "B"};
sR /@ {lis1, lis2}
{{"a", "1", "cefg", "2"},
{"a", "1", "cefg", "2", "345", "AB"}}
splitAndJoin /@ {lis1, lis2}
{{"a", "1", "cefg", "2"},
{"a", "1", "cefg", "2", "345", "AB"}}