Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Test Alpha (1-3)

Please help me

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading