Created
December 14, 2024 17:18
-
-
Save nd3i/90789f85b4d53f945cc0ca2ab2859095 to your computer and use it in GitHub Desktop.
Question re a string containing a regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Question: why do #s 1 & 2 work, but #3 does not? | |
| ## | |
| my @w = <cat bat rat>; | |
| my $s = 'the cattle was rattle by the battery'; | |
| say '1: ', $s.subst(/ <|w>( @w )\w* /, {$0}, :g); | |
| ## Output> the cat was rat by the bat | |
| say '2: ', $s.subst(/ <|w>( cat || rat || bat )\w* /, {$0}, :g); | |
| ## Output> the cat was rat by the bat | |
| my $re = '<|w>( cat || rat || bat )\w*'; | |
| say '3: ', $s.subst(/ <$re> /, {$0}, :g); | |
| ## Output> Use of Nil in string context ... (3x) | |
| ## Output> the was by the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment