get only numbers from string 1

get only numbers from string

/*get only numbers from string*/

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 ,

Here is what the above code is Doing:
1. str.replace(‘Rs. ‘, ”)
This will replace all occurences of Rs. with an empty string.

2. str.replace(‘Rs. ‘, ”).replace(/,/g, ”)
This will replace all occurences of , with an empty string.

3. str.replace(/Rs. |,/g, ”)
This will replace all occurences of Rs. or , with an empty string.

Similar Posts