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

Find your perfect match with regular expressions

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for Alex Alex
October 24, 2019

Find your perfect match with regular expressions

Regex is hard. Here are 4 (maybe 5) quick tips and lesser known features to write good looking and readable regular expressions.

These slides are from a 4 minute lightning talk at FullStack Europe 2019. Sorry for any duplicate slides. Keynote has a hard time exporting the animations to PDF.

Avatar for Alex

Alex

October 24, 2019
Tweet

Other Decks in Programming

Transcript

  1. @alexvanderbist –Some guy, probably “If all you have is a

    hammer, every problem looks like a nail.”
  2. @alexvanderbist /^ # match h \# # literal (?: [a-fA-F0–9]{6}

    # 6 chara | # or [a-fA-F0–9]{3} # 3 chara ) $/x
  3. @alexvanderbist /^ # match hex color \# # literal hashtag

    (?: [a-fA-F0–9]{6} # 6 character hex | # or [a-fA-F0–9]{3} # 3 character hex ) $/x
  4. @alexvanderbist Surviving regex 1. Consider not using regular expressions 2.

    Use extended mode (x-flag) 3. Name your capture groups
  5. @alexvanderbist Surviving regex 1. Consider not using regular expressions 2.

    Use extended mode (x-flag) 3. Name your capture groups 4. Sub-routine definitions when necessary