Need someone to lead product or development at your software company? I lead product and engineering teams and I'm looking for my next opportunity. Check out my resume and get in touch.

Filename regex

Freshness Warning
This article is over 17 years old. It's possible that the information you read below isn't current.

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

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";

Your comments:

Text only, no HTML. URLs will automatically be converted to links. Your email address is required, but it will not be displayed on the site.

Name:

Not your company or your SEO link. Comments without a real name will be deleted as spam.

Email: (not displayed)

If you don't feel comfortable giving me your real email address, don't expect me to feel comfortable publishing your comment.

Website (optional):

Recently Written

Software engineering manager interview questions (Aug 6)
Here are some questions I like to use to get a sense of who an engineering manager is and how they work.
A framework for onboarding new employees (May 15)
There’s no single good way to onboard an employee that works for every role. Here's a framework for creating a process that you can adapt to each situation.
TV hosts as a guide for software managers (May 10)
Software managers can learn a lot from journalists or late night TV hosts and how they interview people.
The Improvement Flywheel (Apr 29)
An incredible flywheel for the improvement of a development team. Fix a few things, and everything starts getting better.
Managers and technical ability (Dec 26)
In technical fields, the closer you are to the actual work being done, the closer your skills need to resemble those of the people doing the work.
Dysfunctions of output-oriented software teams (Sep 17)
Whatever you call it, the symptom is that you're measuring your progress by how much you build and deliver instead of measuring success by the amount of customer value you create.
Evaluative and generative product development (Aug 30)
Customers never even talk to the companies that don't fit their needs at all. If the only product ideas you're considering are those that meet the needs of your current customers, then you're only going to find new customers that look exactly like your current customers.
Product Manager Career Ladder (Aug 19)
What are the steps along the product management career path?

Older...

What I'm Reading

Contact

Adam Kalsey

+1 916 600 2497

Resume

Public Key

© 1999-2020 Adam Kalsey.