我编写了一些java代码将字符串拆分为字符串数组。首先,我使用正则表达式模式分割该字符串"\\,\\,|\\,"
,然后使用模式分割"\\,|\\,\\,"
。为什么第一个输出和第二个输出有区别?
public class Test2 {
public static void main(String[] args){
String regex1 = "\\,\\,|\\,";
String regex2 = "\\,|\\,\\,";
String a = "20140608,FT141590Z0LL,0608103611018634TCKJ3301000000018667,3000054789,IDR1742630000001,80507,1000,6012,TCKJ3301,6.00E+12,ID0010015,WADORI PURWANTO,,3000054789";
String ss[] = a.split(regex1);
int index = 0;
for(String m : ss){
System.out.println((index++)+ ": "+m+"|");
}
}
}
使用时的输出regex1
:
0: 20140608|
1: FT141590Z0LL|
2: 0608103611018634TCKJ3301000000018667|
3: 3000054789|
4: IDR1742630000001|
5: 80507|
6: 1000|
7: 6012|
8: TCKJ3301|
9: 6.00E+12|
10: ID0010015|
11: WADORI PURWANTO|
12: 3000054789|
使用时regex2
:
0: 20140608|
1: FT141590Z0LL|
2: 0608103611018634TCKJ3301000000018667|
3: 3000054789|
4: IDR1742630000001|
5: 80507|
6: 1000|
7: 6012|
8: TCKJ3301|
9: 6.00E+12|
10: ID0010015|
11: WADORI PURWANTO|
12: |
13: 3000054789|
我需要一些解释正则表达式引擎在处理这种情况时是如何工作的。