syntax ?

Documentation for syntax ? assembled from the following types:

language documentation Regexes

From Regexes

(Regexes) regex quantifier ?

The ? quantifier makes the preceding atom match zero or once.

For example, to match dog or dogs, you can write:

/ dogs? /

language documentation Regexes

From Regexes

(Regexes) regex ?

By default, quantifiers request a greedy match:

'abababa' ~~ /.* a/ && say ~$/;   # OUTPUT: «abababa␤» 

You can attach a ? modifier to the quantifier to enable frugal matching:

'abababa' ~~ /.*? a/ && say ~$/;   # OUTPUT: «aba␤» 

You can also enable frugal matching for general quantifiers:

say '/foo/o/bar/' ~~ /\/.**?{1..10}\//;  # OUTPUT: «「/foo/」␤» 
say '/foo/o/bar/' ~~ /\/.**!{1..10}\//;  # OUTPUT: «「/foo/o/bar/」␤» 

Greedy matching can be explicitly requested with the ! modifier.