Josh Greifer Josh Greifer - 1 year ago 55
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download