String s = "99100060000_TXN_CSTM_INFO_0000_20130719_I_0001_0001.xml.err";
如何分隔出来
99100060000
TXN_CSTM_INFO
0000
20130719
I
0001
0001
“TXN_CSTM_INFO”为变长字符串 其他都为定长字符串
正则表达式String
如何分隔出来
99100060000
TXN_CSTM_INFO
0000
20130719
I
0001
0001
“TXN_CSTM_INFO”为变长字符串 其他都为定长字符串
正则表达式String
String s = "99100060000_TXN_CSTM_INFO_0000_20130719_I_0001_0001.xml.err";
Pattern pat = Pattern.compile("(_?\\d+_?|[_a-zA-Z]+)");
Matcher mat = pat.matcher(s);
while (mat.find()) {
String str = mat.group();
int i = str.lastIndexOf("_");
if (i != -1) {
System.out.println(str.substring(0, i));
} else {
System.out.println(str); }
}
}
// Pattern pat = Pattern.compile("(_?\\d+_?|[_a-zA-Z]+)");
Pattern pat = Pattern
.compile("99100060000_(.*?)_0000_20130719_I_0001_0001.xml.err");
Matcher mat = pat.matcher(s);
while (mat.find()) {
String str = mat.group(1);
System.out.println(str);
}
String s = "99100060000_TXN_CSTM_INFO_0000_20130719_I_0001_0001.xml.err";
Matcher m = Pattern.compile("\\d_([a-zA-Z_]+?)_\\d").matcher(s);
while(m.find()){
System.out.println(m.group(1));
}
}