i wanted to write a file search program where the user can enter the serach pattern(any valid regex) and the file name matching the same will be returned.
e.g MFile123.tx will find UMFile123.txt and AIIMFile123.txs
I tried the following, but it did not work:
import java.util.regex.*;
public class regexTest {
public static void main(String... a){
String file="UMFile123.txt";
//String pattern="*MFile*.tx?"; TRIED with \*MFile*.tx , but no use
String pattern="UMFile*.tx?";
Pattern p=Pattern.compile(pattern);
Matcher m=p.matcher(file);
if(m.matches()){
System.out.println("Hi!it matches!!");
}
}
}