81,092
社区成员
发帖
与我相关
我的任务
分享
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String str = "[02:31.00][02:24.00][01:36.00][01:27.00][00:09.00]Ay,Iyaiyai";
Pattern p = Pattern.compile("((\\[\\d\\d:\\d\\d\\.\\d\\d\\])+)(.*)");
Matcher m = p.matcher(str);
while (m.find()) {
String time = m.group(1);
String lyric = m.group(3);
System.out.println(time + ":" + lyric);
}
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String str = "[02:31.00]A[02:24.00]B[01:36.00][01:27.00][00:09.00]Ay,Iyaiyai";
Pattern p = Pattern.compile("(\\[\\d\\d:\\d\\d\\.\\d\\d\\])([^\\[\\]]*)");
Matcher m = p.matcher(str);
while (m.find()) {
String time = m.group(1);
String lyric = m.group(2);
System.out.println(time + lyric);
}
}
}
[02:31.00]A
[02:24.00]B
[01:36.00]
[01:27.00]
[00:09.00]Ay,Iyaiyai
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String lyric = "";
List<String> timeAndLyric = new ArrayList<String>();
String str = "[02:31.00][02:24.00][01:36.00][01:27.00][00:09.00]Ay,Iyaiyai";
Pattern p = Pattern.compile("((\\[\\d\\d:\\d\\d\\.\\d\\d\\])+)(.*)");
Matcher m = p.matcher(str);
while (m.find()) {
lyric = m.group(3);
}
p = Pattern.compile("\\[\\d\\d:\\d\\d\\.\\d\\d\\]");
m = p.matcher(str);
while (m.find()) {
String time = m.group();
timeAndLyric.add(time + ":" + lyric);
}
for (String s : timeAndLyric) {
System.out.println(s);
}
}
}
[02:31.00]:Ay,Iyaiyai
[02:24.00]:Ay,Iyaiyai
[01:36.00]:Ay,Iyaiyai
[01:27.00]:Ay,Iyaiyai
[00:09.00]:Ay,Iyaiyai