假设我有一个表示"Hello123"
的字符串,如何将它们分隔成s[0] = "Hello", s[1] = "123"
?我希望使用s.split()
,但我不知道在参数/参数中放什么。
答案 0 :(得分:3)
您可以使用正则表达式:
String[] splitArray = subjectString.split(
"(?x) # verbose regex mode on \n" +
"(?<= # Assert that the previous character is... \n" +
" \\p{L} # a letter \n" +
") # and \n" +
"(?= # that the next character is... \n" +
" \\p{N} # a digit. \n" +
") # \n" +
"| # Or \n" +
"(?<=\\p{N})(?=\\p{L}) # vice versa");
分割
psdfh123sdkfjhsdf349287
到
psdfh
123
sdkfjhsdf
349287