开发者

RegEx for extracting image file links

开发者 https://www.devze.com 2023-03-24 17:01 出处:网络
What would be the best way to use RegEx to extract links of picture files from a large string? http开发者_StackOverflow://<linkhere>.jpg

What would be the best way to use RegEx to extract links of picture files from a large string?

http开发者_StackOverflow://<linkhere>.jpg
http://<linkhere>.png
http://<linkhere>.gif

etc.? But in one expression?


http://(\\S+?)\\.(jpg|png|gif)

e.g.:

string s = "http://link1.jpg bha http://link2.png blahblah http://link3.gif";
foreach (Match m in Regex.Matches(s, "http://(\\S+?)\\.(jpg|png|gif)"))
{
    Console.WriteLine(m.Groups[1].Value);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消