This is the blog of Adam Kalsey. Unusual depth and complexity. Rich, full body with a hint of nutty earthiness.
Freshness Warning
This blog post is over 20 years old. It's possible that the information you read below isn't current and the links no longer work.
4 Apr 2003
I’ll probably need this again sometime, and someone else might find it useful, so here’s a Perl regex that will strip invalid characters from a Windows filename.
s/[^\w\&%'`\-\@{}~!#\(\)&_\^\+,\.=\[\]]//g
also from a lazy perl hacker -- Great idea, but the expression is too limiting (and you forgot to include the space char). Here's an update -- #!/usr/bin/perl # Stripping illegal chars from Windows filenames. # illegal chars from: http://en.wikipedia.org/wiki/Filename # Bill Wong. use strict; #illegal character sets for various Windows systems. my $illegalHPFS = q#/|\?*#; my $illegalNTFS = $illegalHPFS . '\x00-\x1f'; my $illegalWIN95 = $illegalNTFS . '+' . '\\]' . '\\['; #=============================================== # begin test #=============================================== my $newname = "foo/bar|blech+[]\\doo? [whop]*di \x06and \x10:colon"; print "newname = $newname\n"; #=============================================== #pick the conversion that suits your needs: #=============================================== $newname =~ s/[$illegalHPFS]/_/g; print "converted HPFS title = $newname\n"; $newname =~ s/[$illegalNTFS]/_/g; print "converted NTFS title = $newname\n"; $newname =~ s/[$illegalWIN95]/_/g; print "converted WIN95 title= $newname\n";
This discussion has been closed.
Guy
July 28, 2004 6:39 PM
Thanks dude, I was looking for a filename regexp and finally found one (yes, i'm a lazy perl hacker)