Josh Greifer Josh Greifer - 8 months ago 46
Perl Question

Perl regex - confusing colons

What function do the colons serve in this Perl regex I found in some production code? I know they're used to delimit adverbs, but I'm still unsure what they're doing here.

The code is parsing a uri, and the second line uses the captured group.

if ($r->uri =~ m:/copy/(\d+):) {
my $ref = $1;


After the m, any character can act as the delimiter, so the colons are replacing the standard /'s and lets them become a normal character.

From perlrequick:

the // default delimiters for a match can be changed to arbitrary delimiters by putting an 'm' out front