c#正则表达式.匹配url

zsyok 2010-08-10 10:09:57
string str="http://fsdf.com/sf/wef.jsnmbnmhttp://fwe.com/sf/adf.jsbnmnhttp://hjg.com/sf/adf.jsbmnbhttp://jyt.com/sf/adf.js";

匹配结果http://fsdf.com/sf/wef.js
http://fwe.com/sf/adf.js
http://hjg.com/sf/adf.js
http://jyt.com/sf/adf.js
如何实现.
...全文
121 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zsyok 的回复:]
string str = "http://fsdf.com/sf/wef44jsnmbnmhttp://fwe.com/sf/adf.jsbnmnhttp://hjg.com/sf/adf.jsbmnbhttp://jyt.com/sf/adf.jsas";
你的结果是:
http://fsdf.com/sf/wef44jsnmbnmhttp://fwe.com/sf/adf.js//这里不符合
[/Quote]

拜托,看下你这个字符串和你顶楼的字符串
4楼的wef44js这里不是wef44.js,难道遇到js你就要分开?
jrl5365 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lxcnn 的回复:]
try...


C# code
string str = "http://fsdf.com/sf/wef.jsnmbnmhttp://fwe.com/sf/adf.jsbnmnhttp://hjg.com/sf/adf.jsbmnbhttp://jyt.com/sf/adf.js";
Regex reg = new Regex(@"(?i……
[/Quote]

高手来了!!
zsyok 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lxcnn 的回复:]
try...


C# code
string str = "http://fsdf.com/sf/wef.jsnmbnmhttp://fwe.com/sf/adf.jsbnmnhttp://hjg.com/sf/adf.jsbmnbhttp://jyt.com/sf/adf.js";
Regex reg = new Regex(@"(?i……
[/Quote]

string str = "http://fsdf.com/sf/wef44jsnmbnmhttp://fwe.com/sf/adf.jsbnmnhttp://hjg.com/sf/adf.jsbmnbhttp://jyt.com/sf/adf.jsas";
你的结果是:
http://fsdf.com/sf/wef44jsnmbnmhttp://fwe.com/sf/adf.js//这里不符合
http://hjg.com/sf/adf.js
http://jyt.com/sf/adf.js
Peter200694013 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 peter200694013 的回复:]
其中的“nmbnm”什么意思?
我觉得可以用split来分割
[/Quote]
sorry,没看清url之间不全是nmbnm


string str = "http://fsdf.com/sf/wef.jsnmbnmhttp://fwe.com/sf/adf.jsbnmnhttp://hjg.com/sf/adf.jsbmnbhttp://jyt.com/sf/adf.js";

Regex re = new Regex(@"([\w-]+\.)+[\w-]+.([^a-z])(/[\w- ./?%&=]*)?|[a-zA-Z0-9\-\.][\w-]+.([^a-z])(/[\w- ./?%&=]*)?\.js");

foreach (Match m in re.Matches(str))
Console.WriteLine(m.Value);
-过客- 2010-08-10
  • 打赏
  • 举报
回复
try...

            string str = "http://fsdf.com/sf/wef.jsnmbnmhttp://fwe.com/sf/adf.jsbnmnhttp://hjg.com/sf/adf.jsbmnbhttp://jyt.com/sf/adf.js";
Regex reg = new Regex(@"(?is)http://.*?\.js");
MatchCollection mc = reg.Matches(str);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n";
}
Peter200694013 2010-08-10
  • 打赏
  • 举报
回复
其中的“nmbnm”什么意思?
我觉得可以用split来分割

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧