I have a list:

lis = {"20","ab","Cd","10","E"}

in which I would like to join adjacent elements if they are letters and not digits, to give:

res = {"20","abCd","10","E"}

Again thanks for any help!


2 Answers 2


Maybe something like this:

StringJoin /@ SplitBy[lis, LetterQ]


That doesn't work if there are adjacent non-letter strings. Try this instead:

If[AllTrue[#, LetterQ], StringJoin[#], Splice[#]] & /@ SplitBy[lis, LetterQ]

Another option:

Flatten[SequenceSplit[lis, {str__?LetterQ} :> StringJoin[str]]]
  • $\begingroup$ Works well. Thanks! $\endgroup$
    – Suite401
    Aug 31, 2022 at 2:41
lis = {"20", "ab", "Cd", "10", "E"}

Using SequenceReplace:

SequenceReplace[lis, {s__String?(StringFreeQ[DigitCharacter])} .. :> 

{"20", "abCd", "10", "E"}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.