regex &&

Documentation for regex && assembled from the following types:

language documentation Regexes

From Regexes

(Regexes) regex &&

Matches successfully if all &&-delimited segments match the same substring of the target string. The segments are evaluated left to right.

This can be useful for augmenting an existing regex. For example if you have a regex quoted that matches a quoted string, then / <quoted> && <-[x]>* / matches a quoted string that does not contain the character x.

Note that you cannot easily obtain the same behavior with a lookahead, that is, a regex doesn't consume characters, because a lookahead doesn't stop looking when the quoted string stops matching.

say 'abc' ~~ / <?before a> && . /;    # OUTPUT: «Nil␤» 
say 'abc' ~~ / <?before a> . && . /;  # OUTPUT: «「a」␤» 
say 'abc' ~~ / <?before a> . /;       # OUTPUT: «「a」␤» 
say 'abc' ~~ / <?before a> .. /;      # OUTPUT: «「ab」␤»