How to extract month of the mm/dd/yyyy date using RegExp

Last updated on:

In my current project, I'm getting and extracting date, in mm/dd/yyyy format, form the string, I explained how to do it in a previous blog post, but then later on I need to extract month out of it, here is how you do it using RegExp and replaceAll method:

public static String getMonthFromDebugger(String month){
String[] test;
test = month.split("/", 3);
String m = test[0];
String d = test[1];
String y = test[2];
System.out.println("The day is " + d);
System.out.println("The month is " + m);
System.out.println("The year is " + y);

month = month.replaceAll("\\/([a-zA-Z0-9]{0,})", "");
return month;

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.