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.

Laziness and greediness 102Replace "Hello"Result:When the sheep says “Hello”, the cow will reply, “Hello”Note: Just a reminder: when we use the text-editor’s Replace-All, as opposed to just a singleReplace action, it’s the text editor that continues looking for matching pattern, not the regex engine.<strong>The</strong> regex engine is revved up twice to match both instances <strong>of</strong> the pattern. If we didn’t use ReplaceAll, the resulting text would be:When the sheep says “Hello”, the cow will reply, “Baa! Baa!”Exercise: HTML to Markdown anchors<strong>The</strong> Markdown language is a popular, alternative way to write HTML. It’s not important to knowHTML or Markdown for this exercise; all you need to know is what an anchor link looks like in bothsyntaxes:In HTML:Some linkIn Markdown, that same link is:[Some link](http://example.com)Markdown is popular because it’s easier to read and write – in fact, this whole book is written inMarkdown. However, web browsers don’t interpret Markdown. Usually web developers write inMarkdown and use a separate utility to transfer it to HTML (and back).So, given:Today, I built a website which is nowlisted on various search engines.Write a regex to change it to Markdown syntax:Today, I built a [website](http://example.com) which is now listed [onvarious search engines](http://www.google.com)

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

Saved successfully!

Ooh no, something went wrong!