这是原始的
<embed src="http://flash.site.net/frist.mp3" width="360" height="130" type="application/x-shockwave-media" menu="true" loop="true" play="true"></embed>现在希望用正则匹配出string里面有多少个下面写法的字符串<embed src="任意1.mp3" 任意2 type="application/x-shockwave-media" 任意3></embed>其中任意1是文件路径(本地路径或者网络路径)
任意2\任意3都是任意的东西也可以没有!例如:
----------------------
String =
<embed src="http://flash.site.net/frist.mp3" width="360" height="130" type="application/x-shockwave-media" menu="true" loop="true" play="true"></embed>
<p><body>
<embed src="c:/frist.mp3" height="130" type="application/x-shockwave-media" menu="true" loop="true" play="true"></embed>-----------则结果为2

解决方案 »

  1.   

    用字符串中的查找"<embed "这个有多少个不成吗?
      

  2.   

    Yesterday a man asked a similiar question...
    Please follow this:http://topic.csdn.net/u/20080828/18/42eba401-799a-4d79-8410-b7ff3cb28b55.html
      

  3.   

    楼主是要匹配"<embed "的个数啥正则表达式为:
    /^(\<embed\s)\s(\>)$/
    不知道对不对,楼主可以试一下
      

  4.   


    不行啊如果字符串里面有<embed的字符不就不行了吗?
    必须是这个规范啊!555
      

  5.   

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class RegxEmbedTag { public static void main(String[] args) {
    //<embed\s+[^<>]*src="[^<>\s]+mp3"\s+([^<>]*\s+)?type="application/x-shockwave-media"[^<>]*>.*</embed>
    final String REGEX = "<embed\\s+[^<>]*src=\"[^<>\\s]+mp3\"\\s+([^<>]*\\s+)?type=\"application/x-shockwave-media\"[^<>]*>.*</embed>";
    String test =
    "<embed src=\"http://flash.site.net/frist.mp3\" width=\"360\" height=\"130\" " +
    "type=\"application/x-shockwave-media\" menu=\"true\" loop=\"true\" play=\"true\"> </embed>\n" +
    "<p> <body>\n" +
    "<embed src=\"c:/frist.mp3\" height=\"130\" type=\"application/x-shockwave-media\"" +
    " menu=\"true\" loop=\"true\" play=\"true\"> </embed>";
    Pattern p = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(test);
    int n = 0;
    while (m.find()) {
    System.out.print("第" + (++n) + "个匹配:");
    System.out.println(test.substring(m.start(), m.end()));
    }
    }}
      

  6.   

    最诚挚的谢意给你啊
    sagezk