EasyRegex Logo
EasyRegex
Nuovo

Match Numbers with Optional Minus Sign in JavaScript

javascript

Espressione Regolare

-?\d+(\.\d+)?
Copia

Spiegazione

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

Esempio di Utilizzo

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

Espressioni Regolari Simili