Return only numbers from string

后端 未结 9 2003
名媛妹妹
名媛妹妹 2021-02-05 07:55

I have a value in Javascript as

var input = \"Rs. 6,67,000\"

How can I get only the numerical values ?

Result: 6

9条回答
  •  温柔的废话
    2021-02-05 08:28

    You can use

    str.replace('Rs. ', '').replace(/,/g, '');
    

    or

    str.replace(/Rs. |,/g, '');
    
    • /,/g is a regular expression. g means global
    • /Rs. |,/g is a single regular expression that matches every occurence of Rs. or ,

提交回复
热议问题