0

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

4 Answers 4

1
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/

Sign up to request clarification or add additional context in comments.

Comments

1

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);

http://jsfiddle.net/Qex8J/1/

Comments

1
var vieweeID = str.split('vieweeID=')[1].split('&')[0];

Comments

1
str.match(/vieweeID\=(.*?)\&/)[1]

FIDDLE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.