And*_*ski 2 java regex arrays string split
我有一个看起来像这样的字符串
The#red#studio#502#4
Run Code Online (Sandbox Code Playgroud)
我需要将它分成数组中的3个不同的字符串
s[0] = "The red studio"
s[1] = "502"
s[2] = "4"
Run Code Online (Sandbox Code Playgroud)
问题是第一个应该只有单词而第二个和第三个应该只有数字......
我试图玩这个s.split()方法,但没有运气.
Sri*_*vas 10
String s= "The#red#studio#502#4";
String[] array = s.split("#(?=[0-9])");
for(String str : array)
{
System.out.println(str.replace('#',' '));
}
Run Code Online (Sandbox Code Playgroud)
输出:
The red studio
502
4
Run Code Online (Sandbox Code Playgroud)
Ideone 链接.