use strict;
my $str = '{
"first_page_uri": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/LastMonth.json?PageSize=1000&Page=0",
"end": 387,
"previous_page_uri": null,
"uri": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/LastMonth.json?PageSize=1000&Page=0",
"page_size": 1000,
"start": 0,
"usage_records": [
{
"category": "wireless-usage",
"description": "SIM Usage",
"account_sid": "ACd7a7c24a3c7b0b0ddcde452fd6c18aae",
"start_date": "2023-01-01",
"end_date": "2023-01-31",
"as_of": "2023-02-05T06:53:40+00:00",
"count": "0",
"count_unit": "units",
"usage": "0",
"usage_unit": "units",
"price": "0",
"price_unit": "usd",
"api_version": "2010-04-01",
"uri": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/LastMonth.json?Category=wireless-usage&StartDate=2023-01-01&EndDate=2023-01-31",
"subresource_uris": {
"all_time": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/AllTime.json?Category=wireless-usage",
"today": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Today.json?Category=wireless-usage",
"yesterday": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Yesterday.json?Category=wireless-usage",
"this_month": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/ThisMonth.json?Category=wireless-usage",
"last_month": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/LastMonth.json?Category=wireless-usage",
"daily": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Daily.json?Category=wireless-usage",
"monthly": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Monthly.json?Category=wireless-usage",
"yearly": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Yearly.json?Category=wireless-usage"
}
},
{
"category": "pv-basic-rooms",
"description": "Go Rooms",
"account_sid": "ACd7a7c24a3c7b0b0ddcde452fd6c18aae",
"start_date": "2023-01-01",
"end_date": "2023-01-31",
"as_of": "2023-02-05T06:53:40+00:00",
"count": "0",
"count_unit": "",
"usage": "0",
"usage_unit": "",
"price": "0",
"price_unit": "usd",
"api_version": "2010-04-01",
"uri": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/LastMonth.json?Category=pv-basic-rooms&StartDate=2023-01-01&EndDate=2023-01-31",
"subresource_uris": {
"all_time": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/AllTime.json?Category=pv-basic-rooms",
"today": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Today.json?Category=pv-basic-rooms",
"yesterday": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Yesterday.json?Category=pv-basic-rooms",
"this_month": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/ThisMonth.json?Category=pv-basic-rooms",
"last_month": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/LastMonth.json?Category=pv-basic-rooms",
"daily": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Daily.json?Category=pv-basic-rooms",
"monthly": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Monthly.json?Category=pv-basic-rooms",
"yearly": "/2010-04-01/Accounts/ACd7a7c24a3c7b0b0ddcde452fd6c18aae/Usage/Records/Yearly.json?Category=pv-basic-rooms"
}
},
';
my $regex = qr/,\s*("subresource_uris":.[^}]*[}])/msp;
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