Skip to content
Permalink
Browse files

Add another difference with regexes

I don't know if it's the last one. There might be a myriad more. Maybe it should deserve its own page... Refs #2277
  • Loading branch information...
JJ committed Mar 15, 2019
1 parent e7768f9 commit 17ff3f569cfc0cf39e095344258c0ce49079ada1
Showing with 21 additions and 0 deletions.
  1. +21 −0 doc/Language/5to6-nutshell.pod6
@@ -1117,6 +1117,27 @@ So when the matching process becomes complex, you finally need to have some
understanding of both, especially how LTM strategy works. Besides, C<|> may be
a better choice for grammar reuse.
=head2 Named captures
These work in a slightly different way; also they only work in the latest versions of Perl 5.
=for code :lang<perl5>
use v5.22;
"þor is mighty" =~ /is (?<iswhat>\w+)/n;
say $+{iswhat};
The C<iswhat> within a non-capturing group is used to actuall capture what is
behind, and up to the end of the group (the C<)>). The capture goes to the C<%+>
hash under the key with the name of the capture. In Perl 6
L<named captures work this way|/language/regexes#Capturing_groups>
=for code
"þor is mighty" ~~ /is \s+ $<iswhat>=(\w+)/;
say $<iswhat>;
An actual assignment is made within the regular expression; that's the same
syntax used for the variable outside it.
=comment TODO more rules. Use L<< C<translate_regex.pl> from Blue Tiger|https://github.com/Util/Blue_Tiger/>> in the meantime.
=head3 Comments

0 comments on commit 17ff3f5

Please sign in to comment.
You can’t perform that action at this time.