View Single Post
  #2 (permalink)  
Old 01-31-2008, 05:59 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Regex rules!
Hello

Sorry for the delay. I had to study this topic before I could help you. Using Regex is a bit more complicated than your proposal. I created a program that uses the Regex package to do as you asked.
Code:
package p1; import java.util.regex.*; public class Main { public static void main(String[] args) { /* Regex: (?<=\\.).*$ 1.) (?<=\\.) means lookbehind excluding "." and add 2.) .* means every character until 3.) $ meabs end of string */ String regex = "(?<=\\.).*$", input = "C:\\dir\\filename.ext"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(input); String output = "no match"; if (matcher.find()){ output = matcher.group(); } System.out.println("\t Output: " + output); } }
This will output
Code:
Output: ext
For help on Regex syntax see this link.

This stuff is excellent! I hope that helped you.
__________________
If your ship has not come in yet then build a lighthouse.
Reply With Quote