nev*_*vva 1 .net c# regex string windows-phone-7
可能重复:
从字符串中获取URL
嗨,我试图使用regexp从字符串中提取url.字符串类似于:"lorem ipsum baby www.test.com lorem","lorem ipsum http://www.test.com foo bar"或"lorem www.test.com",没有尾随空格.
using
MatchCollection ms = Regex.Matches(adress, @"(www.+|http.+)([\s]|$)");
返回整个字符串.任何regexp-guru能帮助我解决这个问题吗?
编辑:
解决这个问题:
MatchCollection mc = Regex.Matches(adress, @"(www[^ \s]+|http[^ \s]+)([\s]|$)", RegexOptions.IgnoreCase);
adress = mc[0].Value;
WebBrowserTask task = new WebBrowserTask();
task.URL = adress;
task.Show();
感谢大家的帮助!:)
我认为我们在这里明显缺少这个代码实际上没有任何问题.
也许OP没有正确调用match.value.
string adress = "hello www.google.ca";
// Size the control to fill the form with a margin
MatchCollection ms = Regex.Matches(adress, @"(www.+|http.+)([\s]|$)");
string testMatch = ms[0].Value.ToString();
Run Code Online (Sandbox Code Playgroud)
testMatch仅包含"www.google.ca"
这不是你的意图吗?
| 归档时间: |
|
| 查看次数: |
9397 次 |
| 最近记录: |