日期:2014-05-20 浏览次数:20898 次
1. import java.util.regex.Matcher; 2. import java.util.regex.Pattern; 3. 4. public class DateRegex { 5. 6. public static void main(String[] args) { 7. String[] str = { 8. "2001-00-00", "2001-01-01", "2001-01-30", "2001-01-31", 9. "2001-01-32", "2001-02-01", "2001-02-27", "2001-02-28", 10. "2004-02-29", "2001-02-29", "2001-02-30", "2001-02-31", 11. "2001-02-32", "2001-03-01", "2001-03-10", "2001-03-29", 12. "2001-03-30", "2001-03-31", "2001-03-32", "2001-04-01", 13. "2001-04-10", "2001-04-29", "2001-04-30", "2001-04-31", 14. "2001-04-32", "2001-05-01", "2001-05-10", "2001-05-29", 15. "2001-05-30", "2001-05-31", "2001-05-32", "2001-06-01", 16. "2001-06-10", "2001-06-29", "2001-06-30", "2001-06-31", 17. "2001-06-32", "2001-07-01", "2001-07-10", "2001-07-29", 18. "2001-07-30", "2001-07-31", "2001-07-32", "2001-08-01", 19. "2001-08-10", "2001-08-29", "2001-08-30", "2001-08-31", 20. "2001-08-32", "2001-09-01", "2001-09-10", "2001-09-29", 21. "2001-09-30", "2001-09-31", "2001-09-32", "2001-10-01", 22. "2001-10-10", "2001-10-29", "2001-10-30", "2001-10-31", 23. "2001-10-32", "2001-11-01", "2001-11-10", "2001-11-29", 24. "2001-11-30", "2001-11-31", "2001-11-32", "2001-12-01", 25. "2001-12-10", "2001-12-29", "2001-12-30", "2001-12-31", 26. "2001-12-32", "2001-13-01", "2001-13-10", "2001-13-29", 27. "2001-13-30", "2001-13-31", "2001-13-32", "245-12-04", 28. "100-02-29" , "200-02-29" , "300-02-29" , "400-02-29", 29. "500-02-29" , "800-02-29" , "900-02-29" , "2008-02-29", 30. "1900-02-29", "2000-02-29", "1-01-01" , "1-02-28", 31. "0-01-01" , "1-12-31" , "351-02-29" , "352-02-29", 32. "353-02-29" , "354-02-29" , "355-02-29" , "356-02-29", 33. "357-02-29" , "358-02-29" , "350-02-29" , "1-02-29", 34. "2-02-29" , "3-02-29" , "4-02-29" , "5-02-29", 35. "6-02-29" , "7-02-29" , "8-02-29" , "9-02-29", 36. "10-02-29" , "11-02-29" , "12-02-29" , "13-02-29", 37. "14-02-29" , "15-02-29" , "16-02-29" , "17-02-29", 38. "18-02-29" , "19-02-29" , "20-02-29" , "21-02-29", 39. "22-02-29" , "23-02-29" , "24-02-29" , "25-02-29", 40. "26-02-29" , "27-02-29" , "28-02-29" , "29-02-29", 41. "0-01-12" , "00-01-12" , "000-01-12" , "0000-01-12", 42. "0028-02-29" 43. }; 44. 45. String moreMonth = 46. "(?: \n" + 47. " ## 日期前是大月 \n" + 48. " ## 01 03 05 07 08 \n" + 49. " ## 10 12 月 \n" + 50. " (?<= \n" + 51. " (?: \n" + 52. " 0[13578] \n" + 53. " | \n" + 54. " 1[02] \n" + 55. " ) \n" + 56. " - \n" + // 分隔符 57. " ) \n" + 58. " (?: \n" + 59. " ## 大月的日期 29 \n" + 60. " 29 \n" + 61. " | \n" + 62. " ## 大月的日期 30~31 \n" + 63. " 3[01] \n" + 64. " ) \n" + 65. ") \n"; 66. 67. String lesserMonth = 68. "(?: \n" + 69. " ## 日期前是小月 \n" + 70. " ## 04 06 09 11 月 \n" + 71. " (?<= \n" + 72. " (?: \n" + 73. " 0[469] \n" + 74. " | \n" + 75. " 11 \n" + 76. " ) \n" + 77. " - \n" + // 分隔符 78. " ) \n" + 79. " (?: \n" + 80. " ## 小月的日期 29 \n" + 81. " 29 \n" + 82. " | \n" + 83. " ## 小月的日期 30~31 \n" + 84. " 30 \n" + 85. " ) \n" + 86. ") \n"; 87.