• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Simple Regular expression problem (dont know how to do ..new 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 ...

"/home/john2/MA2/data2/exp2/wed/submission30";

I would like to get "wed"...

Thanks so much for your time
0
micro_learner
Asked:
micro_learner
  • 3
1 Solution
 
CEHJCommented:
Easier in this case to do:

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

http://java.sun.com/docs/books/tutorial/extra/regex/
0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now