The Bastards Book of Regular Expressions
With Membership
Suggested price

The Bastards Book of Regular Expressions

Finding Patterns in Everyday Text

About the Book

This is a spinoff of a chapter from the Bastards Book of Ruby. Regular expressions are an essential and useful skill even outside of programming. They can serve not only as a handy tool for anyone whose work involves writing or data, but also act as a gateway into more interesting and complex kinds of programming. While you're waiting for me to finish this experiment in self-publishing, you can get a good start by reading the massive chapter on regular expressions in the BBoR

About the Author

Dan Nguyen
Dan Nguyen

Dan Nguyen is the author of the still-incomplete Bastards Book of Ruby and Photography. He is currently Head of Data at Skift and was formerly a news application developer at the investigative newsroom, ProPublica.

Table of Contents

  • Regular Expressions are for Everyone
  • FAQ
  • Release notes & changelog
  • Getting Started
  • Finding a proper text editor
  • Why a dedicated text editor?
  • Windows text editors
  • Mac Text Editors
  • Sublime Text
  • Online regex testing sites
  • A better Find-and-Replace
  • How to find and replace
  • The limitations of Find-and-Replace
  • There’s more than find-and-replace
  • Your first regex
  • Hello, word boundaries
  • Word boundaries
  • Escape with backslash
  • Regex Fundamentals
  • Removing emptiness
  • The newline character
  • Viewing invisible characters
  • Match one-or-more with the plus sign
  • The plus operator
  • Backslash-s
  • Match zero-or-more with the star sign
  • The star sign
  • Specific and limited repetition
  • Curly braces
  • Curly braces, maximum and no-limit matching
  • Cleaning messily-spaced data
  • Anchors: A way to trim emptiness
  • The caret as starting anchor
  • The dollar sign as the ending anchor
  • Escaping special characters
  • Matching any letter, any number
  • The numeric character class
  • Word characters
  • Bracketed character classes
  • Matching ranges of characters with brackets and hyphens
  • All the characters with dot
  • Negative character sets
  • Negative character sets
  • Capture, Reuse
  • Parentheses for precedence
  • Parentheses for captured groups
  • Correcting dates with capturing groups
  • Using parentheses without capturing
  • Optionality and alternation
  • Alternation with the pipe character
  • Optionality with the question mark
  • Laziness and greediness
  • Greediness
  • Laziness
  • Lookarounds
  • Positive lookahead
  • Negative lookahead
  • Positive lookbehind
  • Negative lookbehind
  • The importance of zero-width (TODO)
  • Regexes in Real Life
  • Why learn Excel?
  • The limits of Excel (todo)
  • Delimitation
  • Mixed commas and other delimiters
  • Dealing with text charts (todo)
  • Completely unstructured text (todo)
  • Moving in and out and into Excel
  • From Data to HTML (TODO)
  • Simple HTML tricks
  • Example Domain
  • Tabular data to HTML tables
  • Mocking full web pages from data
  • Visualizations
  • The Exercises
  • Data Cleaning with the Stars
  • Normalized alphabetical titles
  • Make your own delimiters
  • Finding needles in haystacks (TODO)
  • Shakespeare’s longest word
  • Changing phone format (TODO)
  • Telephone game
  • Ordering names and dates (TODO)
  • Year, months, days
  • Names
  • Preparing for a spreadsheet
  • Dating, Associated Press Style (TODO)
  • Scenario
  • The AP Date format
  • Real-world considerations
  • The limits of regex
  • Sorting a police blotter
  • Sloppy copy-and-paste
  • Start loose and simple
  • Conclusion
  • Converting XML to tab-delimited data
  • The payments XML
  • The pattern
  • Add more delimitation
  • Cleaning up Microsoft Word HTML (TODO)
  • Switching visualizations (TODO)
  • A visualization in Excel
  • From Excel to Google Static Chart
  • From Google Static Charts to Google Interactive Charts
  • Cleaning up OCR Text (TODO)
  • Scenario
  • Cheat Sheet
  • Moving forward
  • Additional references and resources

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub