September 2017
Beginner
402 pages
9h 52m
English
A regex the with the :p or :pos adverb matches the string from a position that is given in the argument of the adverb. The behavior is clearly seen from the following example.
By default, a regex starts from the beginning of the string:
'pineapple' ~~ / (\w+) /;say $0; # pineapple
Due to the greedy nature of \w+, the whole string is consumed and matched. Let us try skipping a few characters and apply the regex to the same string:
'pineapple' ~~ m:p(4)/ (\w+) /;say $0; # apple
This time, only the apple substring will be matched.
An index of the :p adverb also behaves like an anchor. Similar to how ^ ties the regex to the beginning of the string, the :p(N) adverb ties it to the given position. Compare the following two matches:
Read now
Unlock full access