regex for matching strings that have illegal filename characters.

Posted by cchampion on Stack Overflow See other posts from Stack Overflow or by cchampion
Published on 2010-04-26T05:03:12Z Indexed on 2010/04/26 5:13 UTC
Read the original article Hit count: 266

Filed under:
|

I been trying to figure out how this blasted regex for two hours!!! It's midnight I gotta figure this out and go to bed!!!

String str = new String("filename\\");
if(str.matches(".*[?/<>|*:\"{\\}].*")) {
    System.out.println("match");
}else {
    System.out.println("no match");
}

".*[?/<>|*:\"{\\}].*" is my regex expression. It catches everything correctly except the backslash!!! I need to know how to make it catch the backslash correctly please help!

FYI, the illegal characters i'm trying to catch are ? \ / < > | * : " I've got it working exception for the backslash

© Stack Overflow or respective owner

Related posts about regex

Related posts about java