Skip to content

Commit

Permalink
Clarifying "lookaround" assertions according ot answers in rakudo/rak…
Browse files Browse the repository at this point in the history
…udo#3800

Checking item in #2632
  • Loading branch information
JJ committed Jul 18, 2020
1 parent 0d8a081 commit 6eef362
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions doc/Language/regexes.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -1295,16 +1295,21 @@ C<bar> would match with
say "foobaz" ~~ / foo <!before bar> /; # OUTPUT: «foo␤»
Lookahead assertions can be used also with other patterns, like
characters ranges, interpolated variables, subscripts and so on. In such
cases it does suffice to use a C<?>, or a C<!> for the negate form.
For instance, the following lines all produce the very same result:
Lookahead assertions can be used also with other patterns, like characters
ranges, interpolated variables subscripts and so on. In such cases it does
suffice to use a C<?>, or a C<!> for the negate form. For instance, the
following lines all produce the very same result:
say 'abcdefg' ~~ rx{ abc <?before def> }; # OUTPUT: «「abc」␤»
say 'abcdefg' ~~ rx{ abc <?[ d..f ]> }; # OUTPUT: «「abc」␤»
my @ending_letters = <d e f>;
say 'abcdefg' ~~ rx{ abc <?@ending_letters> }; # OUTPUT: «「abc」␤»
Metacharacters can also be used in lookahead or -behind assertions.
say "First. Second" ~~ m:g/ <?after ^^ | "." \s+> <:Lu>\S+ /
# OUTPUT: «(「First.」 「Second」)␤»
A practical use of lookahead assertions is in substitutions, where
you only want to substitute regex matches that are in a certain
context. For example, you might want to substitute only numbers
Expand Down

0 comments on commit 6eef362

Please sign in to comment.