You want to strip a string of characters that aren’t valid in Windows filenames. For example, you have a string with the title of a document that you want to use as the default filename when the user clicks the Save button the first time.
|Regex options: None|
Leave the replacement text blank.
\/:"*?<>| are not valid in
Windows filenames. These characters are used to delimit drives and
folders, to quote paths, or to specify wildcards and redirection on
the command line.
We can easily match those characters with the character class
The backslash is a metacharacter inside character classes, so we need
to escape it with another
backslash. All the other characters are always literal characters
inside character classes.
We repeat the character class with a ‹
+› for efficiency. This way, if the string
contains a sequence of invalid characters, the whole sequence will be
deleted at once, rather than character by character. You won’t notice
the performance difference when dealing with very short strings, such
as filenames, but it is a good technique to keep in mind when you’re
dealing with larger sets of data that are more likely to have longer
runs of characters that you want to delete.
Since we just want to delete the ...