将字符串中的所有链接和电子邮件地址与列表数组匹配的最简单方法是什么?我preg_match
在 PHP 中使用,但在 C# 中看起来会有所不同。
问问题
617 次
2 回答
1
假设您已经有一个有效的正则表达式,您可以使用Regex
class,如下所示:
static readonly Regex linkFinder = new Regex(@"https?://[a-z0-9.]+/\S+|\s+@\S+\.\S+", RegexOptions.IgnoreCase);
foreach(Match match in linkFinder.Matches(someString)) {
//Do things...
string url = match.Value;
int position = match.Index;
}
于 2010-06-09T14:04:43.233 回答