[英]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.我的输入是包含字符和特殊符号的字符串,我只需要数值 output 那么我们如何使用 Node JS 来做到这一点。 const myInput = "56,57FS+2d" //desired output is 56,57
For character not fixed with FS it will be change.对于 FS 未固定的字符,它将被更改。 Thanks in advance.提前致谢。
Use regex /[a-zA-Z](.*)/g
使用正则表达式/[a-zA-Z](.*)/g
const myInput = "56,57FS+2d"; console.log(myInput.replace(/[a-zA-Z](.*)/g, ''))
Try this, this will select all numbers and ,
and remove everything after +
(here +2d
).试试这个,这将选择所有数字和,
并删除+
之后的所有内容(此处为+2d
)。
const myInput = "56,57FS+2d"; console.log(myInput.replace(/[^0-9,][^+]{0,}/g, ""));
Output:输出:
56,57
const myInput = "56,57FS+2d" var numb = myInput.match(/\\d/g); numb = numb.join(""); console.log(numb)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.