Simple Regular expression problem (dont know how to do to Java )

Hi ..I am relatively new to Java ..( I have always used Perl ..throughout)

This is more of a Reg ex question (simple I assume ) could you please help me

1.With this specific question
2.Point me to material where I can brush my knowledge regarding this ...

I take the directory path from the user in Linux

say dirPath="/home/john/MA/data/exp/feb7th/submission21";

I would Like to get the value "feb7th" from this string ...the properties being
1.this will alaways be the second last in the string (in terms of / slashes)
2.All the paths will end with submission expect that the appended number will be different

With this properies I just want to get the string "feb7th"

Another example would be ...


I would like to get "wed"...

Thanks so much for your time
Who is Participating?
Easier in this case to do:

                  String[] tokens = dirPath.split("/");
                  System.out.println(tokens[tokens.length - 2]);
Here's the info on Java regex. You'll find them compatible with Perl 5:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.