Prev: Capture with quantifier

Reuse capture

you can also reuse the matches within the regex Let's see an example (based on the perl 6 book) to try to find repeated words:

use v6;

my $s = 'The elvish brown fox jumped over the the lazy dog';
if $s ~~ m/ (\w+) \W+ $0 / {
    say $/[0];
# this will print an 'e' which is not what we wanted

Prev: Capture with quantifier

Table of Contents


In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.