gpt4 book ai didi

java - 分开的数字和字母

转载 作者:行者123 更新时间:2023-11-29 05:51:59 25 4
gpt4 key购买 nike

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

最佳答案

你可以使用正则表达式:

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");

split

psdfh123sdkfjhsdf349287

进入

psdfh
123
sdkfjhsdf
349287

关于java - 分开的数字和字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13551985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com