C#正则表达式解析从markdown拉出照片?

时间:2013-05-23 09:44:05

标签: c# regex markdown

降价时的照片看起来像![alt text](src)。我想解析一个降价区块,将所有照片来源都移到IList<string>

我知道正则表达式可能就是答案,但它对我来说就像是一种古老的神秘语言......我如何使用C#将所有照片解析为IList<string>

示例文本

![](http://sphotos-b.xx.fbcdn.net/hphotos-ash3/530402_10151620341829517_1993977231_n.jpg)
When I say "Japanese-Chinese" food I'm not referring to some new type of restaurant      serving both Japanese and Chinese food. This means the restaurant serves Chinese food   prepared for Japanese tastes.

![](http://sphotos-f.ak.fbcdn.net/hphotos-ak-frc1/385269_10151620364269517_1368819859_n.jpg)
This is **subuta** -- sweet and sour pork, this one photo showing the meal set (tenshoku in Japanese). It's one of many Chinese dishes this restaurant serves... and they have **A LOT**!

1 个答案:

答案 0 :(得分:3)

这样的事情应该有效:

!\[.*?\]\(.*?\)

在这里玩,看看它是如何工作的:

http://tinyurl.com/qxjqhcs

var matches = new Regex(@"!\[.*?\]\(.*?\)")
    .Matches(str)
    .Cast<Match>()
    .Select(m => m.Value)
    .ToList();