1

假设我有一个字符串说"Hello123",我怎样才能将它们分开成为s[0] = "Hello", s[1] = "123"?我希望使用s.split(),但我不知道在参数/参数中放入什么。

4

1 回答 1

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
于 2012-11-25T14:37:30.640 回答