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

Posted on 2005-04-24
Last Modified: 2010-03-31
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
Question by:micro_learner
    LVL 86

    Accepted Solution

    Easier in this case to do:

                      String[] tokens = dirPath.split("/");
                      System.out.println(tokens[tokens.length - 2]);
    LVL 86

    Expert Comment

    Here's the info on Java regex. You'll find them compatible with Perl 5:
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    This video teaches viewers about errors in exception handling.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now