I think this should work:
function formatPriceFromString(price) { price = price.replace(/[^\d\.\,]+/g, '') // WHEN PRICE FORMAT 1.000,00 if (/\.[^\,\.]+\,/g.test(price)) price = price.replace(/\./g, '').replace(/\,/, '.') // WHEN PRICE FORMAT 1,000.00 else if (/\,[^\,\.]+\./g.test(price)) price = price.replace(/\,/g, '') // WHEN PRICE FORMAT 100,00 OR 100.00 else price = price.replace(/\,/g, '.') return Number(price) } console.log(formatPriceFromString('$1,100.00')) console.log(formatPriceFromString('$1,100,000.00')) console.log(formatPriceFromString('$1,100.00')) console.log(formatPriceFromString('$1.100,00')) console.log(formatPriceFromString('$1.100.000,00')) console.log(formatPriceFromString('$1 100 000,00')) console.log(formatPriceFromString('$1 100 000.00')) console.log(formatPriceFromString('134, 99 PLN'))
LOG 1100 LOG 1100000 LOG 1100 LOG 1100 LOG 1100000 LOG 1100000 LOG 1100000 LOG 134.99
NaNor other errors.