Reputation: 1146
I do not know how to use regex in c#. I'm confused. Here is the URL where i want to exact the id:
https://j-ec.static.com/images/385/3858715.jpg
I just want to get the bolded number.
The regex I try to use is:
Match thumb_id = Regex.Match(url, @"\/(?)\.jpg");
What's wrong?
Any help?
Upvotes: 0
Views: 57
Reputation: 12546
It is an url. You don't need regex for this.
var url = "https://j-ec.static.com/images/385/3858715.jpg";
var id = Path.GetFileNameWithoutExtension(url);
Upvotes: 3
Reputation: 61
You could always do it without Regex:
url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
Upvotes: 0
Reputation: 2402
Use this instead :
Match thumb_id = Regex.Match(url, "http://(\\S+?)\\.(jpg)");
So you have :
foreach (Match m in Regex.Matches(s, "http://(\\S+?)\\.(jpg)"))
{
Console.WriteLine(m.Groups[1].Value);
}
Upvotes: 0