Skip to content

Instantly share code, notes, and snippets.

@jubilatious1
Created November 19, 2020 19:22
Show Gist options
  • Save jubilatious1/e4da45c3020f3c8c745c2c4325e33c6f to your computer and use it in GitHub Desktop.
Save jubilatious1/e4da45c3020f3c8c745c2c4325e33c6f to your computer and use it in GitHub Desktop.
#Raku (i.e. Perl6) "raku-regex-how-to-use-capturing-group-inside-lookaheads"
#examples with capture markers and 'doubled' capture markers:
say 'abc' ~~ / abc /;
#「abc」
say 'abc' ~~ / a <( b )> c/;
#「b」
say 'abc' ~~ / a <( (b) )> c/;
#「b」
# 0 => 「b」
say 'abc' ~~ / a <( b )> (c)/;
#「b」
# 0 => 「c」
say 'abc' ~~ / a <( (b) )> (c)/;
#「b」
# 0 => 「b」
# 1 => 「c」
#examples pertaining to Julio's third regex code-block;
#note: different results from Julio with most-recent Rakudo-2020.10:
say 'abab' ~~ m:g/(a)<?before b>|b/;
#(「a」
# 0 => 「a」 「b」 「a」
# 0 => 「a」 「b」)
say 'abab' ~~ m:g/<((a))>b|b/;
#(「a」
# 0 => 「a」 「a」
# 0 => 「a」)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment