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

Perl 6 Regex

lichtkind
September 05, 2015

Perl 6 Regex

features and syntax of the new reformed Perl Regular Expression

lichtkind

September 05, 2015
Tweet

More Decks by lichtkind

Other Decks in Programming

Transcript

  1. Perl 6 regex

  2. Perl 6 regex In search for perfection

  3. Much is Gone

  4. Something Stayed ops: m//, s/// , tr/// mods: i, g

    capturing: (…) escape: \ quantifier: *, +, ? min. match. suffix: ??, *?, +? alternatives: | match var.: $1 .. $9
  5. Operators

  6. Create A Regex rx/.../

  7. It's The New qr// rx/.../

  8. Apply Rx ~~

  9. Known Since 5.10 ~~

  10. Still Changing In 5.18 ~~

  11. Apply Rx ~~ no more =~

  12. Known Operators m// s///

  13. Rx Methods match comb subst

  14. New Operators ms// ss///

  15. Aliases For: m :s// s :ss///

  16. Modifiers

  17. Modifiers no x

  18. Modifiers no x m s

  19. Modifiers no s e x

  20. Modifiers no s ee x

  21. Modifiers P5 Perl5

  22. Modifiers :P5 :Perl5

  23. Modifiers ~~ m :P5 /.../

  24. Match All :g :global

  25. Match n Times :x(n)

  26. Just nth Match :nth(n)

  27. Search from Pos On :c(n) :continue(n)

  28. Search Only On Pos :p(n) :pos(n)

  29. Spaces Have Meaning :s :sigspace :ss :samespace

  30. Like qw// Only Smarter :s :sigspace :ss :samespace

  31. Lower Line Is For s/// :s :sigspace :ss :samespace

  32. Modifiers :i :ignorecase :ii :samecase

  33. Modifiers :m :ignoremark :mm :samemark

  34. Choose A Level :bytes :chars :codes :graphs

  35. Metachar

  36. Metachar .

  37. Metachar . any char

  38. Metachar .

  39. Metachar .

  40. No Output In Perl 5 perl -e 'print 1 if

    "\n"=~ /./
  41. Do Output In Perl 6 perl6 -e 'say 1 if

    "\n"~~ /./
  42. Metachar . any char

  43. Metachar \N not a newline

  44. Metachar ^ $ You know that

  45. Metachar ^^ $$ linewise

  46. 'a' Wins In Perl 5 perl -E '"ab"=~ /(a|ab)/;say $1'

  47. 'ab' Wins In Perl 6 perl6 -E '"ab"~~/(a|ab)/;say $0'

  48. Metachar | longest wins

  49. Metachar || first wins

  50. Metachar () capt. groups

  51. Metachar [ ] nonecapturing groups

  52. Metachar <[ ]> char classes

  53. Metachar \s space

  54. Metachar \s = \h | \v horizont. or vertic.

  55. Metachar \s = \h | \v \r \n and alike

  56. Metachar \s = \h | \v Spaces, tabs(\t) and alike

  57. Quantifiers

  58. Quantifiers simple have not changed

  59. Five Digits \d ** 5

  60. Five Digits \d ** 5 '12345'

  61. Two to Five Digits \d ** 2..5

  62. Colon Seperated Digits \d+ % ','

  63. Colon Seperated Digits \d+ % ',' '1,2,3,4'

  64. + Trailing Seperator \d+ %% ',' '1,2,3,4,'

  65. Combined \d ** 2..* % ','

  66. Special Var

  67. Match Object $/ last sucessful Match

  68. Named Submatch $/ $/<...>

  69. Named Submatch $/ $/{'...'} $<...>

  70. List Of Matches @()

  71. List Of Matches @() @() = $0 ..

  72. List Of Matches @()[n] @() = $0 .. (no limit)

  73. AoA Of Matches @()[1][2] .(.).(.(.).(.).(...).).

  74. Learn More http://perlcabal.org /syn/S05.html

  75. Thank You