I don't have a code that needs solving, but merely a simple explanation if possible from an example in a book. There isn't much explaining and I just need to know how this line of code checks to make sure the date entered does not occur in April. The [0-35-9] is throwing me off.

`````` Pattern expression = Pattern.compile("J.*\\d[0-35-9]-\\d\\d-\\d\\d");
``````

it looks like that bit has been thoroughly explained right here

One tricky part of the regex in the example is at `.*` part. If I remember correctly, by default regex matching will use greedy algorithm. In other words, it will keep looking for the pattern as far as it could after `.*` to match, not the first match it found.

``````// i.e.
String a = "Jane BD is 10-10-78";
String b = "Jane or Jone BD is 10-10-78 or 09-09-88";
/*
Both string should be matched but the second string would match at 09-09-88 instead of
what you would expect it to match (at 10-10-78).
*/
``````

I just need to know how this line of code checks to make sure the date entered does not occur in April.

it clearly shows [0-35-9] refers to any character that falls within 0 to 3 or 5 to 9 except 4 which is april

screenedcreamy: if that is so: which month is 0?

Stultuske: Your are right. I guess it should have been [1-35-9] if it is required to skip just april.

``````Stultuske: Your are right. I guess it should have been [1-35-9] if it is required to skip just april.
``````

Actually if you look at the whole regex, it is correct to be [0-35-9] in the sense that it is the second digit of a month. However, the regex is flaw by itself (too simple) because it uses `\d` in place of where numbers may or may not be what they are (\d represents any digit of [0-9]).

Thank you everyone. This has been a huge help!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.