The String : $ 22.4969694
Regex Expression : ([.])+
I've tried .test()
, but I'm not trying to get a boolean response, I'm trying to get the length number of the .
character and slice it.
So if .
is detected in the string, it will slice $ 22.
off the string and set the variable value to 4969694
.
Without a regex, it's quite straight forward
var str1 = '$ 22.4969694';
var str2 = '$ 22694';
console.log( str1.split('.').pop() ) // 4969694
console.log( str2.split('.').pop() ); // nothing happens
I am not 100% sure that I follow what you want your final result(s) to look like but this is what I have come up with that may work for you.
Based on what values you want back this works.
let vals = ['$ 22.4969694', '$ 22', '$ 22567.00']
vals.forEach(val => {
let v = val.replace(/^.*\./, '')
console.log(v)
})
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