Monday, May 4, 2009

Regular expression to match valid Windows XP file names

Last week I had some time trying to figure out the way I have to find a regular expression for matching invalid windows file name with an underscore charaacter. You may find it helpful at some times.

//to match valid Windows XP file names. Such a file name consists
//of any sequence of characters other than
// / \ : * ? " < > |

String regexp = "[/\\:*?\"<>|]";
return fileName.replaceAll(regexp, "_");

1 comment:

  1. That's not quite right. There are other limitations. For example, a dot at the end of a filename (no extension) is invalid.