我正在使用下面的程序來分割我的字符串。按字符數字分割字符串
public static void main(String[] args) {
String test = "A1=CA2=BOA2=RA4=O";
String data[] = test.split("[A-a]\\d{1,100}=");
for (String str : data) {
System.out.println("Split data:"+str);
}
}
//Output
Split data:
Split data:C
Split data:BO
Split data:R
Split data:O
//But I want output something like below :
Split data:A1=C
Split data:A2=BO
Split data:A2=R
Split data:A4=O
我如何拆分我的字符串以上述方式
也許這可以工作:http://stackoverflow.com/questions/12001953/javascript-and-regex-split-string-and-keep-the-separator – pdem
爲什麼你不試試這樣嗎? A1 = C,A2 = BO,A3 = R,A4 = O由(',') –
分割你會不會總是2個字符? – thedarkpassenger