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.
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
For help on Regex syntax see this
link.
This stuff is excellent! I hope that helped you.
