Assignment finished - Completed Main and Bonus exercises #1

Merged
peyman merged 10 commits from develop into main 2026-04-25 21:48:14 +00:00
Showing only changes of commit 00c7229a9d - Show all commits
+10 -2
View File
@@ -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;
}