But what's the problem? Maybe you could provide an example of how your code is failing to deal with '/' properly. In the following example I decode your sample JSON, grab the key that looks like a regular expression, compile it as a regular expression, and use it to perform a match.
use strict;
use warnings;
use JSON;
use constant KEY => 0;
use constant VALUE => 1;
my $json_string = <<'END_JSON';
{
"regex" : {
".*/home/members/index.htm.*" : {
"404" : {
"reporting" : "1000",
"paging" : "2000"
}
}
}
}
END_JSON
my @test_strings = qw(
web/home/members/index.htm?garbage=bye
/home/memberzzzz/index.htm?garbage=bye
);
my $decoded_json = JSON->new->decode( $json_string );
# The regex is contained within a hash key.
my $regex_string = (%{$decoded_json->{regex}})[KEY];
my $regex = qr/$regex_string/;
foreach my $test_string ( @test_strings ) {
if( $test_string =~ m/$regex/ ) {
print "Bingo! [$test_string] matches the pattern '$regex_string'\n
+";
}
else {
print "Boo! [$test_string] doesn't match the pattern '$regex_strin
+g'\n";
}
}
No special escaping of '/' here. The qr// operator is convenient.