Implement findDate method

This commit is contained in:
2026-04-23 00:57:00 +03:30
parent 11c748526e
commit 00c7229a9d
+10 -2
View File
@@ -20,7 +20,7 @@ public class BonusExercises {
- Each segment (between dots) must follow same hyphen rules - Each segment (between dots) must follow same hyphen rules
*/ */
public boolean validateEmail(String email) { 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); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email); 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. If no match for a date is found in the string, return null.
*/ */
public String findDate(String string) { 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; return null;
} }