【发布时间】:2015-10-16 04:36:26
【问题描述】:
大家好,我是一名 java 开发人员,但我是 python 的新手,我有这种平静的 java 代码,我想用 python 翻译:
private static String split(String str) {
List<String> output = new ArrayList<String>();
Matcher match = Pattern.compile("[0-9,+]+|[a-z]+|[A-Z]").matcher(str);
while (match.find()) {
output.add(match.group());
}
String result="";
for (String s:output){
result+=s+" ";
}
return result;
}
例如,如果输入为:“aaaa+1”,输出变为:“aaaa +1”。
我已经尝试过使用:
def split(nome):
r = re.findall('\d+|.\D+', nome)
#m = r.match(nome)
print(r)
但不考虑符号 (+)。
这里有其他例子:
auhsuahsAsaasaA+19090 ---> auhsuahsAsaasaA +19090
+67433998AAAAAAA ---> +67433998 AAAAAAA
ARENA-89 ---> ARENA -89
你能帮我找到解决办法吗?
【问题讨论】:
-
"aaaa+1" 输出变成:"aaaa +1" 我不清楚!
-
我想将普通文本从符号和数字中分离出来,这里还有其他例子: auhsuahsAsaasaA+19090 ---> auhsuahsAsaasaA +19090 ; +67433998AAAAAAA ---> +67433998 AAAAAAA ;
-
你必须在你的问题中加入新的例子(不在此处)。
标签: python split numbers symbols