Formula to extract numbers from a text string

前端 未结 3 1546
無奈伤痛
無奈伤痛 2020-12-22 03:40

How could I extract only the numbers from a text string in Excel or Google Sheets? For example:

A1 - a1b23eg67
A2 - 15dgrgr156

Result desir

3条回答
  •  北海茫月
    2020-12-22 03:54

    I would imagine there is a way to pull this off with =RegexExtract but I can't figure out how to get it to repeat the search after the first hit. Often with these regex function implementations there is a third parameter to repeat, but it doesn't look like google implemented it.

    At any rate, the following formula will do the trick. It's just a little roundabout:

    =concatenate(SPLIT( LOWER(A1) , "abcdefghijklmnopqrstuvwxyz" ))
    

    This is converting the string to lower case, then splitting the string using any letter of the alphabet. This will return an array of the numbers left over, which we concatenate back together.


    Update, switched over to =REGEXREPLACE() instead of extract...:

    =regexreplace(A1, "[a-z]", "")
    

    That's a much cleaner and obvious way of doing it than that concat(split()) nonsense.

提交回复
热议问题