regex [ ]

Documentation for regex [ ], assembled from the following types:

language documentation Regexes

From Regexes

(Regexes) regex [ ]

The parentheses in regexes perform a double role: they group the regex elements inside and they capture what is matched by the sub-regex inside.

To get only the grouping behavior, you can use square brackets [ ... ] instead.

if 'abc' ~~ / [a||b] (c) / {
    say ~$0;                # OUTPUT: «c␤» 

If you do not need the captures, using non-capturing groups provides three benefits: they more cleanly communicate the regex intent; they make it easier to count the capturing groups that you do care about; and matching is bit faster.