This regex pattern matches numbers in a string, allowing for an optional minus sign at the beginning. It matches raw numbers or numbers with decimal points.
const str = 'There are 3 apples and -5.25 oranges';
const numbers = str.match(/-?\d+(\.\d+)?/g);
console.log(numbers);
Copy