Camelia
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:

examples/regex2/reuse_capture.p6
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

Comments

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.
Email:
Name: