I'm writing a Node/Express app and I have a text string in a JSON object that I need to pull a URL out of. The URL is different every time, and the string itself has two very similar URL's, and I only want to pull out one.
The only thing I do know is that in the string, the url will always be preceded with the same text.
String:
The following new or updated things match your search criteria.
Link I Need
<http://randomurl.com/Junk/Yay/ThisView.aspx?r=164241242186&s=J
WD&t=JWD>
Link I don't Need
<http://randomurl.com/Junk/Yay/ThisView.aspx?r=164241242186&s=J
WD&t=JWD&m=true>
Search was last updated on April 12th, 2013 @ 14:43
If you wish to unsubscribe from this update...
Out of this string all I need to pull out is the URL under Link I Need, http://randomurl.com/Junk/Yay/ThisView.aspx?r=164241242186&s=J
WD&t=JWD and nothing else. I'm not quite sure how to go about this, any help would be greatly appreciated!
Something like this should work:
var s = "The following new or updated ...";
var regex = /Link I Need\s*<([^>]*)>/;
var match = s.match(regex);
var theUrl = match && match[1];
This assumes that the URL is not split across newlines. If it is, then after you find the match, you need to to
theUrl = theUrl.replace(/\s+/, '')