|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
"temp" above is of course one of the entries in from the PATH environment variable that I'm using for the comparison
|
|
#3
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > regular expressions in java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|