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.

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

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.

Recently Written

Micromanaging and competence (Jul 2)
Providing feedback or instruction can be seen as micromanagement unless you provide context.
My productivity operating system (Jun 24)
A framework for super-charging productivity on the things that matter.
Great product managers own the outcomes (May 14)
Being a product manager means never having to say, "that's not my job."
Too Big To Fail (Apr 9)
When a company piles resources on a new product idea, it doesn't have room to fail. That keeps it from succeeding.
Go small (Apr 4)
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.
Start with a Belief (Apr 1)
You can't use data to build products unless you start with a hypothesis.
Mastery doesn’t come from perfect planning (Dec 21)
In a ceramics class, one group focused on a single perfect dish, while another made many with no quality focus. The result? A lesson in the value of practice over perfection.
The Dark Side of Input Metrics (Nov 27)
Using input metrics in the wrong way can cause unexpected behaviors, stifled creativity, and micromanagement.

Older...

What I'm Reading