String line = "1-1,hello world";
Matcher m = Pattern.compile("^(.*,)(.*\\s)(.*)").matcher(line);
if (m.matches()){
String num = m.group(1);
String title = m.group(2);
String ans = m.group(3);
System.out.println("编号:"+num+",标题:"+title+",答案:"+ans);
}
2. Python中使用正则表达式
import re
line = '1-1,hello world'
num=re.compile(u".*,").findall(line)[0]
title=re.compile(u",.+?\s").findall(line)[0]
ans=re.compile(u"\s.*").findall(line)[0]
print(f'编号:{num},标题:{title},答案:{ans}')