I have a preg_match problem. Here's the string
field[0][price][8]
And the regex
"/([\[]([a-zA-Z0-9\_]+)?[\]])+$/"
I want to check if the string ends with one ore more [ ] and extract all the values inside.
When i put the $ flag, preg_match_all only gets the big and the last found groups. Something similar happens with preg_match.
Output:
array (size=3)
0 =>
array (size=1)
0 => string '[0][price][8]' (length=13)
1 =>
array (size=1)
0 => string '[8]' (length=3)
2 =>
array (size=1)
0 => string '8' (length=1)
This is the desired result, that i get only if i omit the $ flag, which is not ok because i need to check if the string ends with the matched pattern:
array (size=3)
0 =>
array (size=3)
0 => string '[0]' (length=3)
1 => string '[price]' (length=7)
2 => string '[8]' (length=3)
1 =>
array (size=3)
0 => string '[0]' (length=3)
1 => string '[price]' (length=7)
2 => string '[8]' (length=3)
2 =>
array (size=3)
0 => string '0' (length=1)
1 => string 'price' (length=5)
2 => string '8' (length=1)
Any ideas? Thanks a lot!
8or0andpriceas well?0,price,8.