这是原始的
<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
<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
Please follow this:http://topic.csdn.net/u/20080828/18/42eba401-799a-4d79-8410-b7ff3cb28b55.html
/^(\<embed\s)\s(\>)$/
不知道对不对,楼主可以试一下
不行啊如果字符串里面有<embed的字符不就不行了吗?
必须是这个规范啊!555
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()));
}
}}
sagezk