Reputation: 81
I m working with strings in java script, for e.g if i have the below string:
str = "miniprofile-container http://www.linkedin.com/miniprofile?vieweeID=8573&context=anet&view"
i want the ID number "8573" from this type of strings. They are of different length but have the same struct as the above. So kindly help me in achieving it.
I may use the strcpy function, but it will not be a generic approach
Upvotes: 0
Views: 1775
Reputation: 1238
You can also try this if you don't want/need to use regex:
var str = "miniprofile-container http://www.linkedin.com/miniprofile?vieweeID=8573&context=anet&view";
var s1 = str.indexOf("vieweeID=")+"vieweeID=".length;
var matches = str.substring(s1,str.indexOf("&context"))
alert(matches);
Upvotes: 1
Reputation: 14827
var str = "miniprofile-container http://www.linkedin.com/miniprofile?vieweeID=8573&context=anet&view";
var pattern = /[0-9]+/g;
var matches = str.match(pattern); //8573
Demo: http://jsfiddle.net/Qex8J/
Upvotes: 1