Reputation: 17566
var text = "rating-1-gray-3-blue";
i want to get value 13
how can i do this . basically i want to get all integers inside a string .
i tried with parseInt
, but it returns int when the integer value is at the beginning of the string
thanks in advance
Upvotes: 1
Views: 231
Reputation: 46900
var result=text.replace(/[^0-9]/g, '');
This removes all non 0-9 values from your string
Upvotes: 2
Reputation: 145368
You may use regular expressions:
var result = +text.replace(/\D/g, ""); // 13
Upvotes: 4