用于获取文件路径的Regex

用于获取文件路径的Regex,regex,jtable,Regex,Jtable,我有代码向jtable显示文件名。代码如下: StringBuilder nameOfComparedFile = new StringBuilder(); // if (idLexerSelection != getIDLexer()) { nameOfComparedFile.append(file.getCanonicalPath()); // System.out.println(file.getCanonicalPath() + " )"); } 然后,在jtable

我有代码向jtable显示文件名。代码如下:

StringBuilder nameOfComparedFile = new StringBuilder(); // 

if (idLexerSelection != getIDLexer()) {

  nameOfComparedFile.append(file.getCanonicalPath()); // 
  System.out.println(file.getCanonicalPath() + " )");
}
然后,在jtable中显示如下:D:/Data/File.java 我不想更改getCanonicalPath,因为我创建的jtable将用于下一个进程。我的问题是:如何使用regex仅获取文件名来获取文件名:

file.getName()
如果您绝对必须使用正则表达式:

String filename = file.getCanonicalPath().replaceAll(".*[\\\\/](.*)", "$1");

我对使用regexWell很感兴趣,这里有regex版本。它将在所有文件系统(windows和Linux)上工作