You do not need to hide slashes in Java as a language or regular expressions.
Also note that blocks like this:
if (condition) { return true; } else { return false; }
more compactly and readily written as:
return condition;
So, in your case, I believe your method should look something like this:
public boolean checkDate(String dateToCheck) { return dateToCheck.matches("[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]")); }
Please note that this is not a good way to test for valid dates - it is probably worth trying to parse it as a date or, conversely, ideally using an API that allows you to do this without throwing an exception on failure.
Your regular expression can also be written easier:
public boolean checkDate(String dateToCheck) { return dateToCheck.matches("[0-9]{2}/[0-9]{2}/[0-9]{4}")); }
source share