I'm trying to build a regular expression that will detect any character that Windows does not accept as part of a file name (are these the same for other OS? I don't know, to be honest).
These symbols are:
\ / : * ? " |
Anyway, this is what I have: [\\/:*?\"<>|]
The tester over at http://gskinner.com/RegExr/ shows this to be working.
For the string Allo*ha
, the *
symbol lights up, signalling it's been found. Should I enter Allo**ha
however, only the first *
will light up. So I think I need to modify this regex to find all appearances of the mentioned characters, but I'm not sure.
You see, in Java, I'm lucky enough to have the function String.replaceAll(String regex, String replacement). The description says:
Replaces each substring of this string that matches the given regular expression with the given replacement.
So in other words, even if the regex only finds the first and then stops searching, this function will still find them all.
For instance: String.replaceAll("[\\/:*?\"<>|]","")
However, I don't feel like I can take that risk. So does anybody know how I can extend this?