rakunqp

Difference between single pipe and double pipe in Raku Regex (| Vs ||)


There are two types of alternation in Raku's regex: the | and ||. What is the difference ?

say 'foobar' ~~ / foo || foobar /  # 「foo」
say 'foobar' ~~ / foo | foobar /   # 「foobar」

Solution

  • say 'foobar' ~~ / foo || foobar /  # 「foo」 is the first declared
    say 'foobar' ~~ / foo | foobar /   # 「foobar」 is the longest token
    

    More detailed answer in this post