regex preg_match|preg_match_all in php
- by Josh
I'm trying to come up with a regex that constructs an array that looks like the one below, from the following string
$str = 'Hello world [something here]{optional}{optional}{optional}{n possibilities of this}';
So far I have /^(\*{0,3})(.+)\[(.*)\]((?:{[a-z ]+})?)$/
Array
(
[0] => Array
(
[0] => Hello world [something here]{optional}{optional}{optional}{n possibilities of this}
[1] =>
[2] => Hello world
[3] => something here
[4] => {optional}
[5] => {optional}
[6] => {optional}
[7] => ...
[8] => ...
[9] => {n of this}
)
)
What would be a good approach for this? Thanks