views:

296

answers:

3

Among the wall of text that is a pages source; I need to get the video_id,l and t without the quotes so for a section like this.

"video_id": "lUoiKMxSUCw", "l": 105, "sk": "-2fL6AANk__E49CRzF6_Q8F7yBPWdb9QR", "fmt_map": "35/640000/9/0/115,34/0/9/0/115,5/0/7/0/0", "t": "vjVQa1PpcFMbYtdhqxUip5Vtm856lwh7lXZ6lH6nZAg=",

i need the following

lUoiKMxSUCw

105

vjVQa1PpcFMbYtdhqxUip5Vtm856lwh7lXZ6lH6nZAg=

i was told to use "regular expressions" but I'm not to sure how to use them. any help would be nice :)

+1  A: 

I think this sites good for learning, but if you expect code to do your work, sorry..

this looks like a good start : Regular Expressions Usage in C#

And also this site is very helpful

Canavar
A: 

If the order is always the same, you could use this regular expression:

"video_id"\s*:\s*"([^"]*)"\s*,\s*"l"\s*:\s*(\d+)\s*(?:,\s*"[^"]*"\s*:\s*"[^"]*"\s*)*,\s*"t"\s*:\s*"([^"]*)"

Otherwise you should grab each entry in a list and then pick the ones out you need.

Gumbo
+1  A: 

The Regex to use could be:

\"video_id\":\s*\"(?<videoID>.*?)\"(?:.*?)\"l\":\s*(?<l>.*?),(?:.*?)\"t\":\s*\"(?<t>.*?)\"

Here's some sample code to get you up and running:

string sample = "\"video_id\": \"lUoiKMxSUCw\", \"l\": 105, \"sk\": \"-2fL6AANk__E49CRzF6_Q8F7yBPWdb9QR\", \"fmt_map\": \"35/640000/9/0/115,34/0/9/0/115,5/0/7/0/0\", \"t\": \"vjVQa1PpcFMbYtdhqxUip5Vtm856lwh7lXZ6lH6nZAg=\",";
string regPattern = "\\\"video_id\\\":\\s*\\\"(?<videoID>.*?)\\\"(?:.*?)\\\"l\\\":\\s*(?<l>.*?),(?:.*?)\\\"t\\\":\\s*\\\"(?<t>.*?)\\\"";
Regex reg = new Regex(regPattern, RegexOptions.Singleline);
if (reg.IsMatch(sample))
{
    Match m = reg.Match(sample);
    GroupCollection gColl = m.Groups;
    Console.WriteLine("VideoID:{0}", gColl["videoID"].Value);
    Console.WriteLine("l:{0}", gColl["l"].Value);
    Console.WriteLine("t:{0}", gColl["t"].Value);
}

Don't forget to import "System.Text.RegularExpressions". ;-)

Cerebrus
care to break down the provided code so i can understand what makes it work more.
Fatal510