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 [ ... ] which, by default, don't capture.

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

If you do not need the captures, using non-capturing [ ... ] groups provides the following benefits: