This question already has an answer here:
My string:
fields[name_1]
I want to get fields
and name_1
using regex.
I'm know about preg_match_all()
, but I'm not friends with regular expressions.
</div>
This question already has an answer here:
My string:
fields[name_1]
I want to get fields
and name_1
using regex.
I'm know about preg_match_all()
, but I'm not friends with regular expressions.
</div>
This can be used for direct match:
$string = 'fields[name_1]';
preg_match('/(.+)\[(.+)\]/', $string, $matches);
print_r($matches);
You get:
Array
(
[0] => fields[name_1]
[1] => fields
[2] => name_1
)
So, $matches[1]
and $matches[2]
are what you needed.
Still I am unclear about your exact need!
Here are the explanation for the Regex: