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.

Capture, Reuse 85A backreference in TextWrangler’s Find and ReplaceFixing misshapen dates is one <strong>of</strong> my most common daily uses for regexes. Dates usually contain anobvious pattern, e.g. 9/5/2010 and 4-7-99. To get them into a different format – e.g. 9/5/10 and04/07/1999 – can <strong>of</strong>ten be accomplished with regex techniques.Exercise: Change the order <strong>of</strong> date partsIn American day-to-day usage, dates are <strong>of</strong>ten formatted as month-day-year:03-09-200111-14-201205-22-1978However, programmers prefer dates to be in year-month-day format:2001-03-092012-11-141978-05-22Why? A common operation is to “find the earliest/latest date.” To sort date strings, thesimplest method for a program is to do it an alphabetical-fashion. Think <strong>of</strong> how you sort wordsalphabetically:

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

Saved successfully!

Ooh no, something went wrong!