Results 1 to 2 of 2
Thread: Regex for file extension
- 01-30-2008, 08:06 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 17
- Rep Power
- 0
- 01-31-2008, 03:59 PM #2
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.
This will outputJava 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); } }
For help on Regex syntax see this link.Java Code:Output: ext
This stuff is excellent! I hope that helped you. :DEyes dwelling into the past are blind to what lies in the future. Step carefully.
Similar Threads
-
How to make delete particular extension file from a directory
By Java Tip in forum java.ioReplies: 0Last Post: 04-05-2008, 10:13 AM -
Doubt in simultaneous 'implementation' and 'extension'
By ajaygargnsit in forum New To JavaReplies: 2Last Post: 12-20-2007, 09:33 AM -
Regex pattern
By ravian in forum New To JavaReplies: 4Last Post: 12-11-2007, 10:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks