62,615
社区成员
发帖
与我相关
我的任务
分享
//测试
public class test{
public static void main(String args[]) throws Exception{
java.util.regex.Pattern p = java.util.regex.Pattern.compile("^4\1");
java.util.regex.Matcher m = p.matcher("12454");
if(m.find())
System.out.println(m.group());
//String sysDate = new java.text.SimpleDateFormat("yyyyMMdd_HH_mm_ss").format(Calendar.getInstance().getTime());
//System.out.println(sysDate);
//for(int i=0;i<128;i++)
// System.out.println(i+","+((char)i));
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("test.java")));
String x = "";
String y = "";
while((x=br.readLine())!=null)
y += x+"\n";
br.close();
String s = "2\"13\\\"//23\\\"857\"6\n2\"13\"/*23\"857\"6";
s = y;
String tmp = "",result = "",tmp_2="";
char[] c = s.toCharArray();
boolean b1 = true,b2 = false;
Map<String,String[]> map = new HashMap<String,String[]>();
map.put("\"",new String[]{"\"","\n"});
map.put("//",new String[]{"\n"});
map.put("/*",new String[]{"*/"});
s += "\n";
String clouser[] = null;
for(int i=0;i<c.length-1;i++){
/*
if(x2==0&&x1==0&&c[i]=='/')
x1++;
else if(x2==0&&x1==1&&c[i]=='/')
x1++;
else if(x2==0&&x1==1&&c[i]=='*')
x1+=2;
else if(x1<2&&x2==0&&c[i]=='"')
x2++;
else if(x2==1&&c[i]=='"')
x2--;
else if(c[i]=='\n')
x2=x1=0;*/
tmp = ""+c[i]+c[i+1];
if(tmp.equals("\\\"")){tmp_2+=tmp;i++;
continue;}else if(tmp.equals("\\\\")){tmp_2+=tmp;i++;
continue;}
if(b1){
if(map.containsKey(""+c[i])){
b1 = false;
b2 = true;
clouser = (String[])map.get(""+c[i]);
tmp_2 = "";
continue;
}else if(map.containsKey(tmp)){
b1 = b2 = false;
clouser = (String[])map.get(tmp);
tmp_2 = "";
i++;
continue;
}
}else{
//System.out.println("========="+clouser+","+c[i]+(clouser.charAt(0)==c[i]));
if(clouser!=null){
for(int j=0;j<clouser.length;j++){
//System.out.println(java.util.Arrays.asList(clouser));
if(clouser[j].charAt(0)==c[i]||clouser[j].equals(tmp)){
if(c[i]=='\n')
tmp_2 = "";
clouser = null;
if(b2)
result += tmp_2+"\n";
tmp_2 = "";
b1=true;
b2=false;
break;
}}}
}
tmp_2+=c[i];
//System.out.println(b2+","+result+","+tmp);
}
System.out.println(s);
System.out.println(result);
String s22 = "2中ss文+" + "2yin\\\"中文\"" + "2中文"; //String s = "2中ss文+" + "2yin\\\"中文\"" + "2中文";
String s23 = "2中ss文+" + "2yin\\\"中文\"" + "2中文"; /*String s = "2中ss文+" + "2yin\\\"中文\"" + "2中文";
String s = "2中ss文+" + "2yin\\\"中文\"" + "2中文";
String s = "2中ss文+" + "2yin\\\"中文\"" + "2中文";*/String s25 = "2中ss文x+" + "2yin\\\"中文\"" + "2中文";
String s24 = "2中ss文+" + "2yin\\\"中文\"" + "2中/*文"+"2中ss文+" + "2yin\\\"中文\"" + "2中文";
//new Sudoku(3,new int[][]{{0,3,5},{0,6,4},{1,8,1},{2,0,7},{2,3,2},{3,3,9},{3,7,5},{4,2,6},{5,1,4},{5,2,1},{5,6,3},{6,4,4},{6,6,8},{6,8,6},{7,0,9},{7,8,5},{8,5,1}});
//{13,14,15},{3,4,8},{6,4,7},{9,3,12},{8,3,4},{10,8,14},{12,5,13},{10,4,10},{0,1,7},{1,2,1},{1,8,4}}
}
}
^4\1
12454
test.java
\n
2\"13\\\"//23\\\"857\"6\n2\"13\"/*23\"857\"6
\"
\"
\n
//
\n
/*
*/
\n
\\\"
\\\\
\n
2中ss文+
2yin\\\"中文\"
2中文
2中ss文+
2yin\\\"中文\"
2中文
2中ss文x+
2yin\\\"中文\"
2中文
2中ss文+
2yin\\\"中文\"
2中/*文
2中ss文+
2yin\\\"中文\"
2中文
F:\java>
if(comment1.reset(str).matches() || comment2.reset(str).matches()) {
continue;
}
由于去掉了首尾的空格,可以改为:
if(str.startsWith("//") || (str.startsWith("/*") && str.endsWith("*/"))) {
continue;
}