use strict;
my $str = '{
"Users": {
"RCYzpiJLRkcUfaPi7Pxu1OxGFTi2": {
"Active": "ON",
"Country": "country1",
"Email": "email1",
"ID": "RCYzpiJLRkcUfaPi7Pxu1OxGFTi2",
"Img": "imglink1",
"UserName": "username1",
"videos491375": "videolink1",
"videos748628": "videolink2"
},
"ZqOOX8nUSuVYI9YY9jkub22kWTP2": {
"Active": "ON",
"Country": "country2",
"Email": "username2",
"ID": "ZqOOX8nUSuVYI9YY9jkub22kWTP2",
"Img": "imglink1",
"UserName": "username2",
"videos1096589": "videolink1",
"videos12385": "videolink2",
"videos552833": "videolink3"
},
"ZqOOX8nUSuVYI9YY9jkub22kWTP2": {
"Active": "ON",
"Country": "country3",
"Email": "email3",
"ID": "ZqOOX8nUSuVYI9YY9jkub22kWTP2",
"Img": "imglink",
"UserName": "username3",
},
"mJozWrOKLqgdUPpZhZfinIxiKy92": {
"Active": "ON",
"Country": "country4",
"Email": "emailuser",
"ID": "mJozWrOKLqgdUPpZhZfinIxiKy92",
"Img": "imglink",
"UserName": "username4",
"videos361534": "videolink1"
}
}
}';
my $regex = qr/(?:\"|\')(?<key>[\w\d]+)(?:\"|\')(?:\:\s*)(?:\"|\')?(?<value>[\w\s-]*)(?:\"|\')?/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html