I want to replace or extend the following sample strings not arrays in php
"data" in "[data]"
"data[key]" in "[data][key]"
"data[key1][key2]" in "[data][key1][key2]"
"data[key1][key2][]" in "[data][key1][key2]"
"data[]" in "[data]"
and so on. I tried something with preg_replace but i couldt not find the correct pattern