74
Perl 6 regex

Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Perl 6 regex

Page 2: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Perl 6 regex

In search for perfection

Page 3: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Many Things Gone

Page 4: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Some Stayedcapturing: (…) escape: \

mods: i, gquantifier: *, +, ?

alternatives: |match var.: $/

min. match. suffix: ??, *?, +?

Page 5: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Operators

Page 6: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Create A Regex

rx/.../

Page 7: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

It's The New qr//

rx/.../

Page 8: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Apply Rx

~~,

Page 9: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Known Since 5.10

~~,

Page 10: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Still Changing In 5.18

~~,

Page 11: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Apply Rx

~~, no more =~

Page 12: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Operators

m// s///

Page 13: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Rx Methods

match combsubst

Page 14: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Operators

ms// ss///

Page 15: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Operators

m :s// s :ss///

Page 16: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

no x

Page 17: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

no x m s

Page 18: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

no s e x

Page 19: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

no s ee x

Page 20: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

P5 Perl5

Page 21: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

:P5 :Perl5

Page 22: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

~~ m :P5 /.../

Page 23: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

:g :global

Page 24: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Match x Times

:x(n)

Page 25: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Just nth Match

:nth(n)

Page 26: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Search from Pos On

:c(n) :continue(n)

Page 27: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Search Only On Pos

:p(n) :pos(n)

Page 28: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Spaces Have Meaning

:s :sigspace:ss :samespace

Page 29: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Like qw// Only Smarter

:s :sigspace:ss :samespace

Page 30: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Lower Line Is For s///

:s :sigspace:ss :samespace

Page 31: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

:i :ignorecase:ii :samecase

Page 32: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Modifiers

:m :ignoremark:mm :samemark

Page 33: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Choose A Level

:bytes :chars:codes :graphs

Page 34: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

Page 35: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

.

Page 36: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

.

any char

Page 37: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

.

Page 38: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

.

Page 39: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

No Output In Perl 5

perl -e 'print 1 if "\n"=~ /./

Page 40: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Do Output In Perl 6

perl6 -e 'say 1 if "\n"~~ /./

Page 41: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

.

any char

Page 42: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

\N

not a newline

Page 43: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

^ $

You know that

Page 44: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

^^ $$

linewise

Page 45: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

'a' Wins In Perl 5

perl -E '"ab"=~ /(a|ab)/;say $1'

Page 46: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

'ab' Wins In Perl 6

perl6 -E '"ab"~~/(a|ab)/;say $0'

Page 47: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

|

longest wins

Page 48: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

||

first wins

Page 49: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

()

capt. groups

Page 50: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar[ ]

nonecapturing groups

Page 51: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

<[ ]>

char classes

Page 52: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

\s

space

Page 53: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

\s = \h | \v

horizont. or vertic.

Page 54: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

\s = \h | \v

\r \n and alike

Page 55: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Metachar

\s = \h | \v

Spaces, tabs(\t) and alike

Page 56: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Quantifiers

Page 57: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Quantifiers

simple havenot changed

Page 58: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Five Digits

\d ** 5

Page 59: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Five Digits

\d ** 5

'12345'

Page 60: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Two to Five Digits

\d ** 2..5

Page 61: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Colon Seperated Digits

\d+ % ','

Page 62: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Colon Seperated Digits

\d+ % ','

'1,2,3,4'

Page 63: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

+ Trailing Seperator

\d+ %% ','

'1,2,3,4,'

Page 64: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Combined

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

Page 65: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Special Var

Page 66: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Match Object

$/last sucessful

Match

Page 67: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Named Submatch

$/$/<...>

Page 68: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Named Submatch

$/$/{'...'}$<...>

Page 69: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

List Of Matches

@()

Page 70: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

List Of Matches

@()

@() = $0 ..

Page 71: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

List Of Matches

@()[n]

@() = $0 ..(no limit)

Page 72: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

AoA Of Matches

@()[1][2]

.(.).(.(.).(.).(...).).

Page 73: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Learn More

http://perlcabal.org

/syn/S05.html

Page 74: Perl 6 regex - lichtkind.de · Some Stayed capturing: (…) escape: \ mods: i, g quantifier: *, +, ? alternatives: | match var.: $/ min. match. suffix: ??, *?, +?

Thank You