Forum Discussion

anupambit1797's avatar
anupambit1797
Iron Contributor
Sep 16, 2025
Solved

REGEX+TEXTSPLIT

Dear Experts,

              I have a data like below in column"A":-

And , I want to split it in the way like in "Yellow" So, after each consecutive Alphabet or number it should be splitted, I tried to do something in Column "B" but not succesful. Could you please share any solution if possible by using a comb of regex + textsplit?

Thanks in Advance,

Br,

Anupam

     

  • Hi anupambit1797​ ,

    On the shoulders of giants... or in this case m_tarler​ 's shoulders.

    Try:

    =TEXTSPLIT(LET(a,REGEXEXTRACT(A2,"([A-Z0-9])",1,1),CONCAT(a&IF(a=HSTACK(DROP(a,,1),""),",",""))),",")

    to get what you want - at least what I THINK you want

     

6 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    If without regex we may use

    RepSplit=LAMBDA(txt,
        LET(
        sep, "|",
        engine, LAMBDA(fn,str,
            IF(LEN(str) <= 1, str,
            LET( h, LEFT(str),
                 t, RIGHT(str, LEN(str) - 1),
                 h & IF(h=LEFT(t), sep, "") & fn(fn,t)
            ))
        ),
        rs, LAMBDA(str, engine(engine, str)),
        TEXTSPLIT( rs(txt), sep )
        )
    );

    With Regex we may use peiyezhu​ pattern inside Excel

    =TEXTSPLIT(REGEXREPLACE(A2, "(.)(?=\1)", "\1|"), "|")

    Results are

  • RedNectar's avatar
    RedNectar
    Brass Contributor

    Hi anupambit1797​ ,

    On the shoulders of giants... or in this case m_tarler​ 's shoulders.

    Try:

    =TEXTSPLIT(LET(a,REGEXEXTRACT(A2,"([A-Z0-9])",1,1),CONCAT(a&IF(a=HSTACK(DROP(a,,1),""),",",""))),",")

    to get what you want - at least what I THINK you want

     

  • peiyezhu's avatar
    peiyezhu
    Bronze Contributor

    select *,regreplace('(.)(?=\1)','\1,',id) from Sheet2;

     

    • peiyezhu's avatar
      peiyezhu
      Bronze Contributor

      https://support.microsoft.com/en-us/office/regexreplace-function-9c030bb2-5e47-4efc-bad5-4582d7100897

  • m_tarler's avatar
    m_tarler
    Bronze Contributor

    I'm not good with REGEX so this is probably more complicated than needed but seems to work:

    =LET(a,REGEXEXTRACT(A2,"([A-Z0-9])",1,1),CONCAT(a&IF(a=HSTACK(DROP(a,,1),""),",","")))

Resources