Need someone to lead product management at your software company? I create software for people that create software and I'm looking for my next opportunity. Check out my resume and get in touch.
This is the blog of Adam Kalsey. Unusual depth and complexity. Rich, full body with a hint of nutty earthiness.
Development
Filename regex
Freshness Warning This blog post is over 21 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.
Thanks dude, I was looking for a filename regexp and finally found one (yes, i'm a lazy perl hacker)
Bill Wong November 11, 2005 6:59 PM
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";
When a company piles resources on a new product idea, it doesn't have room to fail. But failing is an important part of innovation. If you can't let it fail, it can't succeed.
The strengths of a large organization are the opposite of what makes innovation work. Starting something new requires that you start with a small team.
Comments
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)
Bill Wong
November 11, 2005 6:59 PM
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.