得一高手指点
我想把 <img alt= "tyui " border= "0 " src= "http://www.sina.com.cn ">
换成 <img alt= "tyui " border= "0 " src= "site/img ">
用js就可以
<script type= "text/javascript ">
var s= " <img alt=\ "tyui\ " border=\ "0\ " src=\ "http://www.sina.com.cn\ "> ";
var regS=/(src=)\ "(.*?)\ "/;
s.match(regS);
alert(s.replace(RegExp.$2, "site/img "));
</script>
可是我放到java里
import java.util.regex.*;
class b{
public static void main(String args[]) {
String regEx= "/(src=)\ "(.*?)\ "/ ";
String str= " <img alt=\ "tyui\ " border=\ "0\ " src=\ "http://www.sina.com.cn\ "> ";
Pattern p=Pattern.compile(regEx);
Matcher m=p.matcher(str);
String s=m.replaceAll( "site/img "); // ( " ") 删除
System.out.println(s);
}
}
输出的结果还是
<img alt= "tyui " border= "0 " src= "http://www.sina.com.cn ">
哪里不对了?盼高手指点阿
------解决方案--------------------
请参考:
public static void main(String[] args)
{
String str = " <img alt=\ "tyui\ " border=\ "0\ " src=\ "http://www.sina.com.cn\ "> ";
String regex = "src=\ ".*\ " ";
str = str.replaceAll(regex, "str=\ "site/img\ " ");
System.out.println( "str is " + str);
}
------解决方案--------------------
不是已经解决了吗?呵呵,你开了这么帖
------解决方案--------------------
学习了
------解决方案--------------------
String regEx= "(? <=src=\ ")(.*?)(?=\ ") ";