要求把一些文件中的“,"%>”替换成正确的格式“,"%>”。就是<%@ page contentType="text/html;charset=gb2312" import="java.util.Vector,java.sql.*,com.project.func.user.*," %>替换成
<%@ page contentType="text/html;charset=gb2312" import="java.util.Vector,java.sql.*,com.project.func.user.*" %>但不知道怎样写正则式,
Pattern plast = Pattern.compile(",\\s\"\\s\\%>");
Matcher m1 = plast.matcher(line);
StringBuffer sb1 = new StringBuffer();
if (m1.find()) {
hasLast = true;
m1.appendReplacement(sb1, "\"%>");
}
m1.appendTail(sb1);
好像不认。我的意思是“,”号与“"”间可能有空白,“"”号与“%>”之间也可能有空白。哪位指点一下,谢谢!
<%@ page contentType="text/html;charset=gb2312" import="java.util.Vector,java.sql.*,com.project.func.user.*" %>但不知道怎样写正则式,
Pattern plast = Pattern.compile(",\\s\"\\s\\%>");
Matcher m1 = plast.matcher(line);
StringBuffer sb1 = new StringBuffer();
if (m1.find()) {
hasLast = true;
m1.appendReplacement(sb1, "\"%>");
}
m1.appendTail(sb1);
好像不认。我的意思是“,”号与“"”间可能有空白,“"”号与“%>”之间也可能有空白。哪位指点一下,谢谢!
System.out.println(str.replaceAll(",\\s*\\\"\\s*%>","\\\"%>"));
对了,如果是全角空格去不掉,需要写进正则里喵~~~~`
这个好像也可以!呵呵!