-2
我有一個字符串= 123456789\ABC 123\ABC123
如何這個字符串分割成兩個
使用正則表達式我已經分成兩本。輸出應該是這樣的
組別1 = 123456789
組2 = 123\ABC123
我有一個字符串= 123456789\ABC 123\ABC123
如何這個字符串分割成兩個
使用正則表達式我已經分成兩本。輸出應該是這樣的
組別1 = 123456789
組2 = 123\ABC123
儘量不要完全改變你的問題使所有答案沒用。如此說來,這是你可以解決你的(新)問題的一個方法:不是第一`/`只是分裂
String str= "123456789\ABC 123\ABC123";
//"\\\\" is required to properly escape the backslash character
String[] split = str.split("\\\\",2); //splits into 2
String group1 = split[0];
//split[1] would now contain the String "ABC 123\ABC123". split it again by whitespace character to obtain `group2`
String[] temp = split[1].split("\\s+",2);
String group2 = temp[1];
爲什麼要使用正則表達式可言,? – azurefrog
我建議你回滾你的編輯,因爲它會使兩個答案的上下文無效。如果你有不同的用例,你應該問一個新的問題(或者更好的,使用提供的答案在這個例子中自己的解決方案) 。 – Mena
@priya:未來,請不要編輯您的問題,以免使現有答案失效。相反,問一個新問題。欲瞭解更多信息,請參閱https://meta.stackoverflow.com/questions/298798/editing-questions-after-initial-post – Matt