More one tutorial FAST AND FURIOUS
I don't know about you, but I have come across many times in many projects needing a function to extract numbers from some string.
And what always happens? Running to stackoverflow, but you don't need more make this.
Just save this post, and you never more need search about this function.
And the code is it:
explaining the code:
In the first we create a function to extract numbers that received a string with a parameter (I make a direct type in the function with if using typescript)
We making a if ternary, and where have a text, this validation with regex will replace anywhere character that not be a number for a void space.
Returning a result from ternary with just numbers.
From post in PT-BR