Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Javascript Remove Negative Decimal Value From String

I am trying to remove the negative and positive decimal value from the string following script remove the positive decimal value from the string however negative is not working

var string = "Test Alpha -0.25 (1-3)"
string = string.replace(/\s*\d+[.,]\d+/g, "");
console.log(string);

above code is returning following output:

Test Alpha - (1-3)

Expected output:

Test Alpha (1-3)

Please help me

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You need add the "-" in the regrex condition.

var string = "Test Alpha -0.25 (1-3)"
string = string.replace(/\s*-\d+[.,]\d+/g, "");
console.log(string);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Change the regex statement to match the -, this can be like so:

/\s*-\d+[.,]\d+/g

about 4 years ago · Juan Pablo Isaza Denunciar

0

The sign should be optional (?), and then you can match a set of numbers followed by a . or a ,, followed by another set of numbers, and replace that match. That way you can match both positive and negative numbers with the same expression.

var string = "Test Alpha 0 -0.25 12,31 31 -123.45 (1-3)"
string = string.replace(/( -?\d+([.,]\d+)?)/g, '');
console.log(string);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda