#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    4
    Rep Power
    0

    Question regular expressions in java


    I'm passing in the PATH environment variable into my java program and I want to compare every entry in the PATH variable to the regular expression *j2sdk* to find out where the jdk is located on the user's machine. However, I don't understand how to do regular expressions in java despite reading the documentation on it. My code is like this:

    Pattern p = Pattern.compile("\\wj2sdk\\w");
    Matcher m = p.matcher(temp);

    Help please.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    4
    Rep Power
    0
    "temp" above is of course one of the entries in from the PATH environment variable that I'm using for the comparison
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    4
    Rep Power
    0

    Thumbs up The Solution


    I figured out the solution if I'm trying to match any string containing the string "j2sdk" using regular expressions

    Pattern p = Pattern.compile("(\\w|\\W)*j2sdk(\\w|\\W)*");

    Yeah, it's nasty isn't it? That's how you do it though.

IMN logo majestic logo threadwatch logo seochat tools logo