2012-09-26 31 views
-1

我正在创建一个wp7应用程序,在他的应用程序m通过web服务检索数据时,在数据中有一些url和邮件ID。但看起来像简单的文字。我如何识别网址和邮件ID?Indentify Mail Id and URL

+0

以哪种方式,你都可以从网上的反应如何? XML或JSON还是纯文本? – nkchandra

回答

1

使用正则表达式。

对于网址:

Regex r = new Regex("(?\w+)://(?[\[email protected]][\w.:@]+)/?[\w.?=%&[email protected]/$,]*");
// Match the regular expression pattern against a text string.
Match m = r.Match(text);
while (m.Success)
{
//do things with your matching text
m = m.NextMatch();
}

对于电子邮件,可以使用另一个正则表达式:

Regex regex = new Regex(@"^([\w.-]+)@([\w-]+)((.(\w){2,3})+)$");