Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Regular Expressions

Regular Expressions

Internal presentation on regular expressions, 2012

John Chandler

November 22, 2012
Tweet

More Decks by John Chandler

Other Decks in Programming

Transcript

  1. Main Flavours POSIX Basic / Extended (default with UNIX tools)

    Perl-derived – very popular! (Perl, Python, PHP, JavaScript, .NET)
  2. Syntax: The First 90% c standard characters . any character

    ^ start of string $ end of string c* zero or more of c
  3. Special Sequences \b beginning / end of word \d decimal

    digit \s whitespace \w alphanumeric and underscore
  4. Repetition s * zero or more + one or more

    ? zero or one {n} exactly n-times {n,m} n to m times
  5. Greedy Matching By default, regular expressions are greedy. They will

    find the biggest match that satisfies an expression.
  6. Writing Regexes Don't if there is a simpler way Build

    regex from small chunks Use the Python and PHP REPLs Document!
  7. Debugging Regexes Don't panic Break regex into smaller chunks Use

    the Python and PHP REPLs Watch out for special characters!