MyException - 我的异常网
当前位置:我的异常网» J2SE » Java简单正则表达式有关问题

Java简单正则表达式有关问题

www.MyException.Cn,网友分享于:2013-01-01   浏览:10次
Java简单正则表达式问题
正则表达式学了忘忘了学太痛苦了,请csdn每天用比较熟悉的同学帮帮忙。

要求:给定html字符串,将图片链接中的文件名中空格去掉

原字符串例子:String s1 = 'ttached muscles. </P><P align=center><IMG height=286 alt="eye_anatomy 1.jpg" src="file:///android_asset/images/eye_ anatomy 1.jpg" width=350 bord'

去除后字符串:String s2 = 'ttached muscles. </P><P align=center><IMG height=286 alt="eye_anatomy 1.jpg" src="file:///android_asset/images/eye_anatomy1.jpg" width=350 bord'

可以确定的是'src="file:///android_asset/images/'肯定存在, 图片链接肯帝有扩展名,有可能是.bmp,.gif,.jpg等等,字符串中可能有若干图片链接,

分不够我可以回帖补.有什么问题可以留言

谢谢

------解决方案--------------------
Java code

String str = "\r\n<P align=center>\r\n"
                + "<IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy 1  .jpg\" width=350 border=0></P> fd ssda f \r\n"
                + "fd  <P align=center><IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/  eye_anato  my 1 .bmp\" width=350 border=0></P>\r\n"
                + "fd  <P align=center><IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/  eye_anato  my 1 .bmp\" width=350 border=0></P>\r\n"
                + "fd  <P align=center><IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/  eye_anato  my 1 .bmp\" width=350 border=0></P>\r\n"
                + "fd  <P align=center><IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/  eye_anato  my 1 .bmp\" width=350 border=0></P>\r\n"
                + "\r\n<IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy1.png\" width=350 border=0>\r\n"
                + "\r\n<IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy1.png\" width=350 border=0>\r\n"
                + "\r\n<IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy1.png\" width=350 border=0>\r\n"
                + "\r\n<IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy1.png\" width=350 border=0>\r\n"
                + "\r\n<IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy1.png\" width=350 border=0>\r\n";

Pattern p = Pattern.compile(
                "(.*?)(src=\"file:///android_asset/images/)(.*?)(\")",
                Pattern.DOTALL);
// nanoseconds 2600356

Pattern p = Pattern.compile(
                "(.*?)(src=\"file:///android_asset/images/)(.*?\\s+.*?)(\")",
                Pattern.DOTALL);
// nanoseconds 6596175
软件开发程序错误异常ExceptionCopyright © 2009-2014MyException 版权所有