How do I specify one or two days in a date string using regular expression

Hi

I'm using regular expression
("\\[d]{2}/\\d{2}/\\d{4}")
to check a date in this format.
dd/mm/yyyy

I would also like to use it check a date in this format
d/m/yyyy, d/mm/yyyy, dd/m/yyyy

What do I change in the regular expression so it realises date can be either dd or d, mm or m

Thanks
MelaniePhilpotAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
armoghanConnect With a Mentor Commented:
This will solve your problem.
Instead of using Reg expression
use simple date format
http://javaalmanac.com/egs/java.text/FormatDate.html
0
 
TimYatesCommented:
("\\[d]{1,2}/\\d{1,2}/\\d{4}")

?
0
 
TimYatesCommented:
Sorry:

("\\d{1,2}/\\d{1,2}/\\d{4}")

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
TimYatesCommented:
or:

    StringTokenizer st = new StringTokenizer( "10/5/1974, 26/8/2004, 3/12/2005, 31/02/2003", "," ) ;
    boolean valid = true ;
    SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy" ) ;
    while( st.hasMoreTokens() )
    {
      String tok = st.nextToken().trim() ;
      try
      {
        Date d = sdf.parse( tok ) ;
        System.out.println( tok + " is a valid date " + d ) ;
      }
      catch( ParseException ex )
      {
        System.out.println( tok + " is not a valid date" ) ;
        valid = false ;
        break ;
      }
    }
    System.out.println( valid ) ;
0
 
TimYatesCommented:
whoops...sorry armoghan...  didn't see your post...
0
 
TimYatesCommented:
:-(
0
 
CEHJCommented:
MelaniePhilpot, what was wrong with Tim's second answer?
0
All Courses

From novice to tech pro — start learning today.