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
We use the '' symbol so that Google Sheets understands that we mean the meta-character 'd' and not the letter 'd'. So if you want to extract a single numeric digit from a string, you use the expression 'd'. But if you want to extract more than one digits, you can use the expression 'd+'.
Extract Numbers from String in Excel (using VBA) Since we have done all the heavy lifting in the code itself, all you need to do is use the formula =GetNumeric(A2). This will instantly give you only the numeric part of the string.
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+", ""))
These work with integers, decimals and negatives:
=REGEXEXTRACT(A2,"-*\d*\.?\d+") =VALUE(REGEXEXTRACT(A2,"-*\d*\.?\d+"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With