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.

Filename regex

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.

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

This discussion has been closed.

Recently Written

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.
Reframe How You Think About Users of your Internal Platform (Nov 13)
Changing from "Customers" to "Partners" will give you a better perspective on internal product development.
Measuring Feature success (Oct 17)
You're building features to solve problems. If you don't know what success looks like, how did you decide on that feature at all?
How I use OKRs (Oct 13)
A description of how I use OKRs to guide a team, written so I can send to future teams.
Build the whole product (Oct 6)
Your code is only part of the product
Input metrics lead to outcomes (Sep 1)
An easy to understand example of using input metrics to track progress toward an outcome.
Lagging Outcomes (Aug 22)
Long-term things often end up off a team's goals because they can't see how to define measurable outcomes for them. Here's how to solve that.

Older...

What I'm Reading

Contact

Adam Kalsey

+1 916 600 2497

Resume

Public Key

© 1999-2024 Adam Kalsey.