0

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.

Tushar
  • 151
  • 3
  • 17

3 Answers3

2

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

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

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
Manas Khandelwal
  • 3,515
  • 2
  • 10
  • 22
0

const myInput = "56,57FS+2d"
var numb = myInput.match(/\d/g);
numb = numb.join("");
console.log(numb)
Sooraj s
  • 277
  • 3
  • 8