regex preg_match|preg_match_all in php

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-05-03T19:57:32Z Indexed on 2010/05/03 20:48 UTC
Read the original article Hit count: 256

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-match