Regex master needed!
I have an variable timestamp coming from the server and I need to find which format is used everytime. I've tried implementing a regex formats but they don't work. I'm fairly new to regex patterns but still I've tried working them up my self or else look for a specific example but couldn't find so I'm asking you.
The formats from the server can look like this:
"2015-02-23 15:27:31 UTC"
or
"2015-01-22T19:38:40Z"
here is the code to find the formats:
private static String getFormat(String time) {
String firstRegEx = "^\\d{4}-\\d{2}-\\d{2}\'T+\'\\d{2}:\\d{2}:\\d{2}\'Z\'$";
String secondRegEx = "^\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2}\\s\\w{3}$";
if (time.toLowerCase().matches(firstRegEx)) {
return firstRegEx;
} else if (time.toLowerCase().matches(secondRegEx)) {
return secondRegEx;
}
return null;
}
Can you look at my regex patterns and tell me what am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire