EasyRegex Logo
EasyRegex
Nuevo

Match Numbers with Optional Minus Sign in JavaScript

javascript

Expresión Regular

-?\d+(\.\d+)?
Copiar
¿Tienes Comentarios?

Explicación

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.

javascript

Ejemplo de Uso

const str = 'There are 3 apples and -5.25 oranges';
const numbers = str.match(/-?\d+(\.\d+)?/g);
console.log(numbers);
Copiar

Expresiones Regulares Similares