Search code examples
regexgoogle-sheetsextractgoogle-sheets-formulaarray-formulas

Extract digits from string - Google spreadsheet


In Google spreadsheets, I need a formula to extract all digits (0 to 9) contained into an arbitrary string, that might contain any possible character and put them into a single cell.

Examples (Input -> Output)

d32Ελληνικάfe9j.r/3-fF66 -> 329366
h01j2j3jFxF$$4j5j6j7j8j9 -> 0123456789

Solution

  • You may replace all non-digit characters using the \D+ regex and an empty string replacement with

    =REGEXREPLACE(A11,"\D+", "")
    

    or with casting it to a number:

    =VALUE(REGEXREPLACE(A11,"\D+", ""))
    

    enter image description here