13.07.2015 Views

Download - The Bastards Book of Regular Expressions

Download - The Bastards Book of Regular Expressions

Download - The Bastards Book of Regular Expressions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Anchors: A way to trim emptiness 57So, in order to remove unneeded spaces at the beginning <strong>of</strong> a line:In English We’re looking to match all whitespace characters that occur at the beginning <strong>of</strong> a line.We want to replace those characters with nothing (i.e. we want to delete them).Find ˆ +Replace (with nothing)This regex only affects lines that begin with one-or-more whitespace characters. For those lines,those whitespace characters are removed.Exercise: Add a common directory to a list <strong>of</strong> filesAs a digital photographer, I run into this scenario all the time: I’ve taken a bunch <strong>of</strong> photos and wantto send them to someone across the world. But with megapixels being so plentiful today, these filesin their raw format can weigh in as much as 10MB to 20MB – too big to send as email attachments.And this client doesn’t have a shared Dropbox.So the easiest way to send them is to upload them to an FTP or web server. On my computer, I dothis by opening the folder, selecting all the files, and dragging them to my server:Moving files<strong>The</strong> client can then download the files at their leisure. What was dog.jpg in my local hard drivecan now be found at:http://www.example.com/images/client-joe/dog.jpgBut how do I tell the client this? Well, first, I select all the filenames on my local hard drive and doa copy-and-paste into a text editor. I get something like:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!