Regular expressions – my secret love

22725c2d3eb331146549bf0d5d3c050c?s=47 stefan judis
December 03, 2019

Regular expressions – my secret love

22725c2d3eb331146549bf0d5d3c050c?s=128

stefan judis

December 03, 2019
Tweet

Transcript

  1. @stefanjudis Regular expressions – my secret love...

  2. ... and things I'm excited about.

  3. /^(Hello|Bonjour) dotJS!(.+)$/ Match a string that...

  4. /^(Hello|Bonjour) dotJS!(.+)$/ Match a string that starts with...

  5. /^(Hello|Bonjour) dotJS!(.+)$/ Match a string that starts with "Hello" or

    "Bonjour"...
  6. /^(Hello|Bonjour) dotJS!(.+)$/ Match a string that starts with "Hello" or

    "Bonjour" followed by " dotJS!"...
  7. /^(Hello|Bonjour) dotJS!(.+)$/ Match a string that starts with "Hello" or

    "Bonjour" followed by " dotJS!", capture more than one character...
  8. /^(Hello|Bonjour) dotJS!(.+)$/ Match a string that starts with "Hello" or

    "Bonjour" followed by " dotJS!", capture more than one character until the end.
  9. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS? How are you?" )

  10. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS? How are you?" ) null

  11. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS? How are you?" ) null

  12. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" )

  13. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: "Hello", 2: " How are you?" ]
  14. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: "Hello", 2: " How are you doing?" ]
  15. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: "Hello", 2: " How are you?" ]
  16. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: "Hello", 2: " How are you?" ]
  17. /^(Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: "Hello", 2: " How are you?" ]
  18. /^(?:Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" )

  19. /^(?:Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: " How are you?" ]
  20. /^(?:Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: " How are you?" ] (?: ...) – there are non-capturing groups in JavaScript
  21. /^(?:Hello|Bonjour) dotJS!(.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: " How are you?" ]
  22. /^(?:Hello|Bonjour) dotJS!(?<rest>.+)$/ .exec( "Hello dotJS! How are you?" )

  23. /^(?:Hello|Bonjour) dotJS!(?<rest>.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: " How are you?", groups: { rest: " How are you?" } ]
  24. /^(?:Hello|Bonjour) dotJS!(?<rest>.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: " How are you?", groups: { rest: " How are you?" } ]
  25. /^(?:Hello|Bonjour) dotJS!(?<rest>.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you doing?", 1: " How are you doing?", groups: { rest: " How are you?" } ] (?<name> ...) – there are named capture groups in JavaScript
  26. /^(?:Hello|Bonjour) dotJS!(?<rest>.+)$/ .exec( "Hello dotJS! How are you?" ) [

    0: "Hello dotJS! How are you?", 1: " How are you doing?", groups: { rest: " How are you?" } ]
  27. /^(Bonjour) \1 dotJS!(?<rest>.+)$/ .exec( "Bonjour dotJS! How are you?" )

  28. /^(Bonjour) \1 dotJS!(?<rest>.+)$/ .exec( "Bonjour dotJS! How are you?" )

    null
  29. /^(Bonjour) \1 dotJS!(?<rest>.+)$/ .exec( "Bonjour Bonjour dotJS! How are you?"

    )
  30. /^(Bonjour) \1 dotJS!(?<rest>.+)$/ .exec( "Bonjour Bonjour dotJS! How are you?"

    ) [ 0: "Hello dotJS! How are you?", 1: "Bonjour" 2: " How are you?", groups: { rest: " How are you?" } ]
  31. /^(Bonjour) \1 dotJS!(?<rest>.+)$/ .exec( "Bonjour Bonjour dotJS! How are you?"

    ) [ 0: "Hello dotJS! How are you doing?", 1: "Bonjour" 2: " How are you?", groups: { rest: " How are you?" } ] \1, \2, ... – there are capture group back references in JavaScript
  32. /^(Bonjour) \1 dotJS!(?<rest>.+)$/ .exec( "Bonjour Bonjour dotJS! How are you?"

    ) [ 0: "Hello dotJS! How are you?", 1: "Bonjour" 2: " How are you?", groups: { rest: " How are you?" } ]
  33. /^(?:Bonjour) dotJS!(?<rest>.+) \k<rest>$/ .exec( "Bonjour dotJS! How are you?" )

  34. /^(?:Bonjour) dotJS!(?<rest>.+) \k<rest>$/ .exec( "Bonjour dotJS! How are you?" )

    null
  35. /^(?:Bonjour) dotJS!(?<rest>.+) \k<rest>$/ .exec( "Bonjour dotJS! How are you? How

    are you?" )
  36. /^(?:Bonjour) dotJS!(?<rest>.+) \k<rest>$/ .exec( "Bonjour dotJS! How are you? How

    are you?" ) [ 0: "Bonjour dotJS! How are you? How are you?", 1: " How are you?", groups: { rest: " How are you?" } ]
  37. /^(?:Bonjour) dotJS!(?<rest>.+) \k<rest>$/ .exec( "Bonjour dotJS! How are you? How

    are you?" ) [ 0: "Bonjour dotJS! How are you? How are you?", 1: " How are you?", groups: { rest: " How are you?" } ] \k<name> – there are named capture group back references in JavaScript
  38. /^(?:Bonjour) dotJS!(?<rest>.+) \k<rest>$/ .exec( "Bonjour dotJS! How are you? How

    are you?" )
  39. /^(?:Bonjour) dotJS!(?<rest>.+)$/ .exec( "Bonjour dotJS! How are you?" )

  40. /^(?:Bonjour) dotJS!(?<rest>.+)$/ .exec( "Bonjour dotJS! How are you?" ) [

    0: "Bonjour dotJS! How are you?", 1: " How are you?", groups: { rest: " How are you?" } ]
  41. /^(?:Bonjour) dotJS!(?<rest>.+)$/ .exec( "Bonjour dotJS! How are\nyou?" )

  42. /^(?:Bonjour) dotJS!(?<rest>.+)$/ .exec( "Bonjour dotJS! How are\nyou?" ) null

  43. /^(?:Bonjour) dotJS!(?<rest>.+)$/s .exec( "Bonjour dotJS! How are\nyou?" )

  44. /^(?:Bonjour) dotJS!(?<rest>.+)$/s .exec( "Bonjour dotJS! How are\nyou?" ) [ 0:

    "Bonjour dotJS! How are↵you?", 1: " How are↵you?", groups: { rest: " How are↵you?" } ]
  45. /^(?:Bonjour) dotJS!(?<rest>.+)$/s .exec( "Bonjour dotJS! How are\nyou?" ) [ 0:

    "Bonjour dotJS! How are↵you?", 1: " How are↵you?", groups: { rest: " How are↵you?" } ] / .../s – the dotall flag really captures every character
  46. /^(?:Bonjour) dotJS!(?<rest>.+)$/s .exec( "Bonjour dotJS! How are\nyou?" )

  47. /^(?:Bonjour) dotJS!(?<rest>.+)\p{Emoji}$/su .exec( "Bonjour dotJS! How are\nyou?" )

  48. /^(?:Bonjour) dotJS!(?<rest>.+)\p{Emoji}$/su .exec( "Bonjour dotJS! How are\nyou?" ) null

  49. /^(?:Bonjour) dotJS!(?<rest>.+)\p{Emoji}$/su .exec( "Bonjour dotJS! How are\nyou?" )

  50. /^(?:Bonjour) dotJS!(?<rest>.+)\p{Emoji}$/su .exec( "Bonjour dotJS! How are\nyou?" ) [ 0:

    "Bonjour dotJS! How are↵you?", 1: " How are↵you?", groups: { rest: " How are↵you?" } ]
  51. /^(?:Bonjour) dotJS!(?<rest>.+)\p{Math_Symbol}$/su .exec( "Bonjour dotJS! How are\nyou?⁼" ) [ 0:

    "Bonjour dotJS! How are↵you⁼?", 1: " How are↵you?", groups: { rest: " How are↵you?" } ]
  52. /^(?:Bonjour) dotJS!(?<rest>.+)\p{Script=Greek}$/su .exec( "Bonjour dotJS! How are\nyou?μ" ) [ 0:

    "Bonjour dotJS! How are↵youμ?", 1: " How are↵you?", groups: { rest: " How are↵you?" } ]
  53. /^(?:Bonjour) dotJS!(?<rest>.+)\p{Script=Greek}$/su .exec( "Bonjour dotJS! How are\nyou?μ" ) [ 0:

    "Bonjour dotJS! How are↵youμ?", 1: " How are↵you?", groups: { rest: " How are↵you?" } ] p/{ ...} – unicode property escapes are a thing these days!
  54. Other exciting "new" features to check out lookahead and lookbehind

    assertions
  55. Other exciting "new" features to check out lookahead and lookbehind

    assertions String.prototype.matchAll
  56. Other exciting "new" features to check out lookahead and lookbehind

    assertions String.prototype.matchAll string replacement patterns
  57. @stefanjudis www.stefanjudis.com Thanks.