日期:2014-05-20  浏览次数:20709 次

求正则表达式匹配标签外的空格
如题,
将:aa    <bb cccc=''>eeee     www   <w oo='eee'>   <qqq  iii='xxx' >  ssss d</a>aaa oooo
<>中间的空格不匹配,其他的每一个空格均替换为“-”

最终:
aa----<bb cccc=''>eeee-----www---<w oo='eee'>---<qqq  iii='xxx' >--ssss-d</a>aaa-oooo
------解决方案--------------------
Try this:


public class Tee{
public static void main(String[] args){
String s = "aa    <bb cccc=''>eeee     www   <w oo='eee'>   <qqq  iii='xxx' >  ssss d</a>aaa oooo";
String regex = " (?=[\\w \\=']*<.*>
------解决方案--------------------
[\\w ]*$)";
System.out.println(s.replaceAll(regex, "-"));
}
}