• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help - Problem with Pattern class  RSS feed

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an attempt to validate a date value we are using the pattern class with regular expressions. Not being familiar with expressions I'm not sure why the YEAR value is bombing and any help would be greatly appreciated.

I am passing a YEAR value that bombs when it comes to validation class we have setup.

Any help would be greatly appreciated.

The values passed in to this code is ("12", "22", "2506").

Here is the code we're using:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Melinda.
What do you mean by "bombs" ? When I tried running this code, it returned false. It didn't blow up or anything.

And it should return false because the regular expression for year says it should begin with "20." While in your calling code, it begins with "25"
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

Thanks for your time and reply. I did find that after I sent this email.

I got it fixed and now it is working famously.

Again many thanks. Regards.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Melinda]: I'm not sure why the YEAR value is bombing and any help would be greatly appreciated.

[...]

The values passed in to this code is ("12", "22", "2506").


Apparently the year is 2506.

[B][/B]

And the year is expected to begin with 20. The ( is a special character indicating the beginning of a capture group (meaning "remember what batches this next section...) and the ^ is a special character indicating the beginning of the input. The 20\\d\\d means 20 followed by a digit and followed by another digit. Unfortunately "2506" does not begin with 20.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!