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
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Leave a Reply

  • Recent Comments

  • Tags

    AACS Adobe Photoshop Elements 6 Apple Apple Lossless C++ C/C++ CNN Customer Service Dell Digikam DRM Firefox FLAC Fortune Fortune-Widget Fortune File Ghosts I-IV Giga-Byte Google Google Analytics Hack Internet Explorer Kernel Kubuntu Lingo Linksys SPA2102 Linux Mandriva Microsoft Nine Inch Nails OpenSuse Parody PC World Performance Perl Plugin Pre-Installed Linux Quote of the Day Restaurant Software Engineering Ubuntu VOIP Widget Wordpress YouTube
  • Stack Overflow

    Gravatar
    Jason Mock
    591r
    39
  •  

    March 2007
    S M T W T F S
    « Feb   Apr »
     123
    45678910
    11121314151617
    18192021222324
    25262728293031
  • Archives

  • Categories

  • Books I'm Reading

    ISBN: 0385504225 ISBN: 020161622X ISBN: 0596100469 ISBN: 0321344758