Extract digits from string - Google spreadsheet
If some of source cells may contain only numbers it is safer to convert the value to text first, then regexreplace. Otherwise it produces error.
Result as text
=REGEXREPLACE(TO_TEXT(C1),"\D+", "")
Result as number
=VALUE(REGEXREPLACE(TO_TEXT(C1),"\D+", ""))
The same for whole column
=ARRAYFORMULA(IF(LEN(C1:C), VALUE(REGEXREPLACE(TO_TEXT(C1:C),"\D+", ""))))
These work with integers, decimals and negatives:
=REGEXEXTRACT(A2,"-*\d*\.?\d+")
=VALUE(REGEXEXTRACT(A2,"-*\d*\.?\d+"))
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+", ""))