大家好!我有一个类似这样的文本:“一些文本和网址 http://test.com 和其他单词。” 我需要使用一个正则表达式来获取网址的部分。
我尝试了以下代码:
我尝试了以下代码:
string text = "Some text with uri http://test.com and other words.";
string pattern = @"\b(\S+)://([^:]+)(?::(\S+))?\b";
MatchCollection matches = Regex.Matches(text, pattern);
当我写下 "Some text with uri http://test.com" 或者 "word1 http://test.com:5000 word2" 时,它可以正常工作。
有什么问题吗?
http://test.com 和其他单词。
对吗? - Justin Morgan