Implement findDate method
This commit is contained in:
@@ -20,7 +20,7 @@ public class BonusExercises {
|
||||
- Each segment (between dots) must follow same hyphen rules
|
||||
*/
|
||||
public boolean validateEmail(String email) {
|
||||
String regex = "^[a-zA-z0-9_+-]+(?:\\.[a-zA-Z0-9_+-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z0-9-]+$"; // todo
|
||||
String regex = "^[a-zA-z0-9_+-]+(?:\\.[a-zA-Z0-9_+-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z0-9-]+$";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(email);
|
||||
|
||||
@@ -39,7 +39,15 @@ public class BonusExercises {
|
||||
If no match for a date is found in the string, return null.
|
||||
*/
|
||||
public String findDate(String string) {
|
||||
// todo
|
||||
String regex1 = "(0[1-9]|1[0-2])\\/(0[1-9]|[12][0-9]|30)\\/\\d{4}|(0[1-9]|[12][0-9]|30)\\/(0[1-9]|1[0-2])\\/\\d{4}";
|
||||
String regex2 = "(\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|30))";
|
||||
String regex3 = "(\\d{4}\\/(0[1-9]|1[0-2])\\/(0[1-9]|[12][0-9]|30))";
|
||||
Pattern pattern = Pattern.compile(regex1 + "|" + regex2 + "|" + regex3);
|
||||
Matcher matcher = pattern.matcher(string);
|
||||
|
||||
if(matcher.find()){
|
||||
return matcher.group();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user