"01:23:45 Computer science is awesome! 10:11:59 I like ICE CREAM." is what this regex is supposed to match.
This is the regex I'm using :
"(\d\d:\d\d:\d\d)\s(.+)\s" Though it's not working...could someone please help me.
Let me specify what I needed done
import java.util.regex.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Friendly {
public static void main(String[] arguments) throws IOException{
String input = new BufferedReader(new InputStreamReader(System.in)).readLine();
Pattern regex = Pattern.compile("(\\d\\d:\\d\\d:\\d\\d)\\s(.+)(?=\\s|$)");
Matcher match;
boolean first = true;
while ((match = regex.matcher(input)).find()){
if (!first)
System.out.println();
else first = !first;
System.out.print(match.group(1) + " ");
String[] timestamp = match.group(1).split(":");
int hour = Integer.parseInt(timestamp[0]) * 9;
int minutes = Integer.parseInt(timestamp[1]) * 3 + Integer.parseInt(timestamp[2]);
boolean isOdd = false;
String[] letters = match.group(2).split("");
for (int index = 0; index < letters.length; index++){
String letter = letters[index];
if (letter != " " && letter.length() > 0){
System.out.printf("0x%02X" + (index == letters.length - 1 ? "" : " "), letter.charAt(0)^(isOdd ? minutes : hour) & 0xFF);
isOdd = !isOdd;
}
}
input = input.substring(input.indexOf(match.group(0)) + 1, input.length());
}
}
}
In this code I'm trying to parse "01:23:45 Computer science is awesome!" then get "10:11:59 I like ICE CREAM."
Sorry if it wasn't clear enough.