Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 4th, 2003, 10:14 AM
anulok anulok is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 4 anulok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #2  
Old March 4th, 2003, 10:48 AM
anulok anulok is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 4 anulok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
"temp" above is of course one of the entries in from the PATH environment variable that I'm using for the comparison

Reply With Quote
  #3  
Old March 5th, 2003, 10:53 AM
anulok anulok is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 4 anulok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > regular expressions in java


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT