Filename Regex

Many time I’ve found myself needing to perform some form of handling / manipulation of filenames and paths in my perls scripts. So I’ve tweaked a regex I found to one that adds an escape ( ‘\’ ) before each special character (allowing either shell or regex to understand the result). I know it’s limited and will only really work for *nix based systems, however I find it quite useful…

s/([\s\/\&%'`\-\@{}~!#\(\)&_\^\+,\.=\[\]])/\\$1/g

Popularity: 1% [?]

Share and Enjoy:
  • Print
  • Identi.ca
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Facebook
  • Twitter
  • Posterous
This entry was posted in Linux, Software Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">