您的位置:程序门 -> .net技术 -> c#



再求url正则表达式


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


再求url正则表达式[已结贴,结贴人:xhustudent]
发表于:2007-03-17 11:35:53 楼主
要提取html页中的图片提示内容(不管它为不为空)     <img   alt= "hello,this   is   test!   012 "     只提取它的   hello,this   is   test!   012   这样的说明文字  


http://www.test.com/scripts/index.php?tn=1&amp;ke=leqgwate

http://afedt.net/scripts/index.php?tn=5&ke=afsedfge

提取url的正则要可以提取任何一网址的形式   比如它也要能提取  

http://45sadfedsafe.bz/scripts/index.php?tn=7&ke=afedtegth

大家帮帮我


发表于:2007-03-17 12:02:481楼 得分:6
看楼主怎么用了,不同的用法可以有不同的写法,你现在这样问,那就写个通用的吧

图片提示内容
(? <= <img[^> ]*?alt= ")[^ "]*?(?= ")

url的
http://(\w+\.)?\w+\.\w+/scripts/index\.php\?(tn ¦tn)=\d+&(amp;)?(ke ¦ke)=\w+
当然如果用在程序中,就可以指定regexoptions.ignorecase,就不用这样写了
matchcollection   mc   =   regex.matches(yourstr,   @ "http://(\w+\.)?\w+\.\w+/scripts/index\.php\?tn=\d+&(amp;)?ke=\w+ ",   regexoptions.ignorecase);
foreach   (match   m   in   mc)
{
          richtextbox2.text   +=   m.groups[0].value   +   "\n ";
}

当然,如果你想提取的是所有的网址,并不局限于你所举的例子,可以这样
matchcollection   mc   =   regex.matches(yourstr,   @ "http(s)?://([\w-]+\.)+[\w-]+(/[\w-   ./?%&=]*)? ",   regexoptions.ignorecase);
foreach   (match   m   in   mc)
{
          richtextbox2.text   +=   m.groups[0].value   +   "\n ";
}
发表于:2007-03-17 12:12:282楼 得分:0
能否再来一个提示

提取     <table>   和   两个 <br>   中间的字符串  

比如:  

<table>   这个中间的什么字符不重要   我先分出大块后再从这个大块中提取     <br> <br>
发表于:2007-03-17 12:16:293楼 得分:4
(? <= <table> )([\s\s]*?)(?= <br> <br> )


快速检索

最新资讯
热门点击