046 Regex

06 Jul 2013

Regular expressions or regex is a symbolic language to describe a pattern of characters so that we can match it with a required set. We can use regex pattern amtching across various programming languages to detect and match patterns as required.

Download video: mp4

Similar episodes: 008 Sublime Text

##Background on Regex

  1. Regex Wikipedia
  2. Regex info
  3. Rubular - Ruby Regex
  4. RegexPal - JavaScript Regex
  5. Regexper - Create Regex

##Things to learn with Regex

  1. open Rubular
  2. match any character with data Sherlock Holmes or hello Benedict Cumberbatch
  1. match neither character with data hello Benedict Cumberbatch
  1. match from the start of line with data http://build-podcast.com with escape sequence


  2. match from start till end with data 5th Symphony

  1. optional match with data me.com/blog or me.com/blog/3
  1. repetition
  1. alternative


  1. Text Editor: Sublime Text



    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam, ipsa amet facilis molestiae asperiores ex eum odio quod similique numquam!


    with Find and Replace to detect all opening and closing tags


  2. Programming Languages: JavaScript

    1. Use RegexPal







    2. Open up the Chrome DevTools - output as an array of matches

      var regex = /<; '<h1>hello</h1>'.match(regex)

  3. Finite-State Automaton : Using RegexPer to draw out a flow diagram that will deconstruct any regex. Using a pattern from 8 Regex you should know

    ^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$ ^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$

##More Resources on Regex 1. Learn to code the hard way: Regex by Zed Shaw 1. Tutsplus Course on Regex 1. Learning Regex 1. Regex reference 1. Parsing HTML the Cthulhu Way and a reply in Stackoverflow

##Build Link of this episode

Bret Victor’s video channel on Vimeo