这是原始的
<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
解决方案 »
- 字符串大小比较
- Java怎么可以在最小化时把一个程序缩小在任务栏图标
- 菜鸟程序,有错误,急啊
- 用户登陆,连接数据库老报错.急啊!!!
- 配置JBDC数据库
- Java里用JComponent.getGraphics()来画图形都不能保存,如何解决。
- 急问,如何通过一个url得到一个File对象?
- 晕 分也用完了 怎么也变2个三角了??呵呵 提问还升级吗?哈哈
- 请问,怎样把Tomcat里的日志文件加到JBuilder里
- 各位虾哥虾妹:偶是新手,想请教什么地方有关于程序设计的练习题目之类的网站,越多越好,偶想多练习一下,可惜找不到题目,如果有买的书也行,谁给推荐一本。
- 高分请教一个过滤器设置的问题?急,急,急,急!
- 关于Servlet程序
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