Josh Greifer Josh Greifer - 2 months ago 7
Perl Question

What does it mean when a regex is delimited by colons?

What function do the colons serve in this Perl regex that I found in some production code?

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


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

Answer

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

Comments