请教一下各位,小弟现在又一个正则表达式需要匹配上网页中的特定链接。比如:
<li class="odd  ">
<span class="msProfileLink"><a title="C++ Phil()" href="http://www.myspace.com/pkinkade"><span class="pilDisplayName">C++ Phil()</span><img src="http://c1.ac-images.myspacecdn.com/images02/117/s_3afde66753014bb5953f9926910e3150.jpg" class="profileimagelink" /><span class="pilRealName">Phil Kinkade</span></a>我需要匹配的特定链接为:http://www.myspace.com/pkinkade,前面必须以http://www.myspace.com/开头,后面跟一串字符,但不可以为空白符,下划线可以。但是字符个数小于等于20。请问该正则表达式应该如何写呢?JAVA里使用我现在有一个,可以匹配出所有的链接,但这样显然不行
String regUrl = "(?<=(href=)[\"]?[\']?)[http://][^\\s\"\'\\?]*[^\\s\"\'>]*";这个太复杂了,我想写简单些的,能满足上面的要求即可、谢谢各位!

解决方案 »

  1.   

    http://www\.myspace\.com/[^ "]{0,20}
      

  2.   


    public static void main(String args[])throws Exception{
              String str="<a title=\"C++ Phil()\" href=\"http://www.myspace.com/pkinkade\">";
              Matcher m= Pattern.compile("http://www\\.myspace\\.com[^ ]{0,20}(?=\")").matcher(str); 
              if(m.find())System.out.println(m.group());
         }
      

  3.   

    意思是指,"http://www.myspace.com/pkinkade">< 
    【"】前面的条件? 也就是【pkinkade】这一块?