I understand the basics of regex but I am not able to create a regular expression satisfying all these conditions. Can anybody give me an idea how to do it.
- The string must be at least 20 character long
- The string must contain a digit
- The digit must be preceded by some non-numeric character
- The end of the string must be a date of format
DD/MM/YYYY HH:MM- yes, there is a space in between and all the digits must be present. Digits occurring in the date part of the string are not considered as satisfiability condition of rule 2. - If there is a
$sign before the first numeric digit occurs, the string is invalid
I have tried using code:
if (sCurrentLine.length() > 20) {
for (int i=0; i <= sCurrentLine.length() - 1; i++) {
char character = sCurrentLine.charAt(i);
int ascii = (int) character;
if (((ascii >= 48) && (ascii <= 57)) && (i!=0)) {
char character2 = sCurrentLine.charAt(i-1);
int ascii2 = (int) character2;
if(!((ascii2 >= 48) && (ascii2 <= 57))) {
//
}
}
}
}
but it seems too complicated.
Is there a regex approach that could solve this?