Tushar
Tushar

Reputation: 192

How to remove alphabets and special character form string

My input is string contains character and special symbol, I need only numeric value output so how can we do that using Node JS. const myInput = "56,57FS+2d" //desired output is 56,57

For character not fixed with FS it will be change. Thanks in advance.

Upvotes: 0

Views: 637

Answers (2)

Nitheesh
Nitheesh

Reputation: 19986

Use regex /[a-zA-Z](.*)/g

const myInput = "56,57FS+2d";
console.log(myInput.replace(/[a-zA-Z](.*)/g, ''))

Upvotes: 2

Manas Khandelwal
Manas Khandelwal

Reputation: 3921

Try this, this will select all numbers and , and remove everything after + (here +2d).

const myInput = "56,57FS+2d";
console.log(myInput.replace(/[^0-9,][^+]{0,}/g, ""));

Output:

56,57

Upvotes: 1

Related Questions