1

Here is an example of what information i'm trying to extract with regex

class="result-title hdrlnk">CHAVY IMPALA</a><span class="result-meta"><span class="result-price">$1300</span>


class="result-title hdrlnk">1950 Buick Super straight 8 with 3 on the tree</a><span class="result-meta"><span class="result-price">$9850</span>


class="result-title hdrlnk">Buick Lesabre Hardtop Coupe</a><span class="result-meta"><span class="result-price">$8800</span>

I was able to successfully get the price but I am having issues with getting the name of the listing for vehicles. Here is an example of the regex

This code works great for getting the price and additional brackets

Regex vg = new Regex(@"</a><span class=""result\-meta""><span class=""result-price"">\$\d+");

I've tried using the period at the beginning but that will only display the last letter or number of the listing title it will not display the entire listing title.

Regex vg = new Regex(@".</a><span class=""result\-meta""><span class=""result-price"">\$\d+");

I've also tried

Regex vg = new Regex(@">.*</a><span class=""result\-meta""><span class=""result-price"">\$\d+");

and

Regex vg = new Regex(@">\d+</a><span class=""result\-meta""><span class=""result-price"">\$\d+");

but no luck with the listing title :( Any help would be appreciated.

fabio
  • 11
  • 2

1 Answers1

1

Try this regex class=\"result-title hdrlnk\">(.*?)<\/a><span class=\"result-meta\"><span class=\"result-price\">(.*?)<\/span>, preferably one listing at the time.

string input = "your input"
string pattern = @"class=\""result-title hdrlnk\"">(.*?)<\/a><span class=\""result-meta\""><span class=\""result-price\"">(.*?)<\/span>");
Match match = Regex.Matches(input, pattern);
string title = match.Groups[1].Value;
string price = match.Groups[2].Value
Nicolas
  • 6,611
  • 3
  • 29
  • 73