74
Perl 6 regex

Writing Perl 6 Rx

Embed Size (px)

DESCRIPTION

Perl 6 is here today ... for some uses, like writing parsing scripts, that would be too complicated for a single Perl 5 regex. This is an overview what has changed.

Citation preview

Page 1: Writing Perl 6 Rx

Perl 6 regex

Page 2: Writing Perl 6 Rx

Perl 6 regex

In search for perfection

Page 3: Writing Perl 6 Rx

Many Things Gone

Page 4: Writing Perl 6 Rx

Some Stayedcapturing: (…) escape: \

mods: i, gquantifier: *, +, ?

alternatives: |match var.: $/

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

Page 5: Writing Perl 6 Rx

Operators

Page 6: Writing Perl 6 Rx

Create A Regex

rx/.../

Page 7: Writing Perl 6 Rx

It's The New qr//

rx/.../

Page 8: Writing Perl 6 Rx

Apply Rx

~~,

Page 9: Writing Perl 6 Rx

Known Since 5.10

~~,

Page 10: Writing Perl 6 Rx

Still Changing In 5.18

~~,

Page 11: Writing Perl 6 Rx

Apply Rx

~~, no more =~

Page 12: Writing Perl 6 Rx

Operators

m// s///

Page 13: Writing Perl 6 Rx

Rx Methods

match combsubst

Page 14: Writing Perl 6 Rx

Operators

ms// ss///

Page 15: Writing Perl 6 Rx

Operators

m :s// s :ss///

Page 16: Writing Perl 6 Rx

Modifiers

no x

Page 17: Writing Perl 6 Rx

Modifiers

no x m s

Page 18: Writing Perl 6 Rx

Modifiers

no s e x

Page 19: Writing Perl 6 Rx

Modifiers

no s ee x

Page 20: Writing Perl 6 Rx

Modifiers

P5 Perl5

Page 21: Writing Perl 6 Rx

Modifiers

:P5 :Perl5

Page 22: Writing Perl 6 Rx

Modifiers

~~ m :P5 /.../

Page 23: Writing Perl 6 Rx

Modifiers

:g :global

Page 24: Writing Perl 6 Rx

Match x Times

:x(n)

Page 25: Writing Perl 6 Rx

Just nth Match

:nth(n)

Page 26: Writing Perl 6 Rx

Search from Pos On

:c(n) :continue(n)

Page 27: Writing Perl 6 Rx

Search Only On Pos

:p(n) :pos(n)

Page 28: Writing Perl 6 Rx

Spaces Have Meaning

:s :sigspace:ss :samespace

Page 29: Writing Perl 6 Rx

Like qw// Only Smarter

:s :sigspace:ss :samespace

Page 30: Writing Perl 6 Rx

Lower Line Is For s///

:s :sigspace:ss :samespace

Page 31: Writing Perl 6 Rx

Modifiers

:i :ignorecase:ii :samecase

Page 32: Writing Perl 6 Rx

Modifiers

:m :ignoremark:mm :samemark

Page 33: Writing Perl 6 Rx

Choose A Level

:bytes :chars:codes :graphs

Page 34: Writing Perl 6 Rx

Metachar

Page 35: Writing Perl 6 Rx

Metachar

.

Page 36: Writing Perl 6 Rx

Metachar

.

any char

Page 37: Writing Perl 6 Rx

Metachar

.

Page 38: Writing Perl 6 Rx

Metachar

.

Page 39: Writing Perl 6 Rx

No Output In Perl 5

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

Page 40: Writing Perl 6 Rx

Do Output In Perl 6

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

Page 41: Writing Perl 6 Rx

Metachar

.

any char

Page 42: Writing Perl 6 Rx

Metachar

\N

not a newline

Page 43: Writing Perl 6 Rx

Metachar

^ $

You know that

Page 44: Writing Perl 6 Rx

Metachar

^^ $$

linewise

Page 45: Writing Perl 6 Rx

'a' Wins In Perl 5

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

Page 46: Writing Perl 6 Rx

'ab' Wins In Perl 6

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

Page 47: Writing Perl 6 Rx

Metachar

|

longest wins

Page 48: Writing Perl 6 Rx

Metachar

||

first wins

Page 49: Writing Perl 6 Rx

Metachar

()

capt. groups

Page 50: Writing Perl 6 Rx

Metachar[ ]

nonecapturing groups

Page 51: Writing Perl 6 Rx

Metachar

<[ ]>

char classes

Page 52: Writing Perl 6 Rx

Metachar

\s

space

Page 53: Writing Perl 6 Rx

Metachar

\s = \h | \v

horizont. or vertic.

Page 54: Writing Perl 6 Rx

Metachar

\s = \h | \v

\r \n and alike

Page 55: Writing Perl 6 Rx

Metachar

\s = \h | \v

Spaces, tabs(\t) and alike

Page 56: Writing Perl 6 Rx

Quantifiers

Page 57: Writing Perl 6 Rx

Quantifiers

simple havenot changed

Page 58: Writing Perl 6 Rx

Five Digits

\d ** 5

Page 59: Writing Perl 6 Rx

Five Digits

\d ** 5

'12345'

Page 60: Writing Perl 6 Rx

Two to Five Digits

\d ** 2..5

Page 61: Writing Perl 6 Rx

Colon Seperated Digits

\d+ % ','

Page 62: Writing Perl 6 Rx

Colon Seperated Digits

\d+ % ','

'1,2,3,4'

Page 63: Writing Perl 6 Rx

+ Trailing Seperator

\d+ %% ','

'1,2,3,4,'

Page 64: Writing Perl 6 Rx

Combined

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

Page 65: Writing Perl 6 Rx

Special Var

Page 66: Writing Perl 6 Rx

Match Object

$/last sucessful

Match

Page 67: Writing Perl 6 Rx

Named Submatch

$/$/<...>

Page 68: Writing Perl 6 Rx

Named Submatch

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

Page 69: Writing Perl 6 Rx

List Of Matches

@()

Page 70: Writing Perl 6 Rx

List Of Matches

@()

@() = $0 ..

Page 71: Writing Perl 6 Rx

List Of Matches

@()[n]

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

Page 72: Writing Perl 6 Rx

AoA Of Matches

@()[1][2]

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

Page 73: Writing Perl 6 Rx

Learn More

http://perlcabal.org

/syn/S05.html

Page 74: Writing Perl 6 Rx

Thank You